diff --git a/src/sync.d b/src/sync.d index 6a8f6604..2da62670 100644 --- a/src/sync.d +++ b/src/sync.d @@ -861,6 +861,12 @@ final class SyncEngine return; } + // Check for HTML ASCII Codes as part of file name + if (!containsASCIIHTMLCodes(path)) { + log.vlog("Skipping item - invalid name (Contains HTML ASCII Code): ", path); + return; + } + final switch (item.type) { case ItemType.dir: uploadDirDifferences(item, path); @@ -1079,6 +1085,12 @@ final class SyncEngine log.vlog("Skipping item - invalid name (Contains an invalid whitespace item): ", path); return; } + + // Check for HTML ASCII Codes as part of file name + if (!containsASCIIHTMLCodes(path)) { + log.vlog("Skipping item - invalid name (Contains HTML ASCII Code): ", path); + return; + } // filter out user configured items to skip if (path != ".") { diff --git a/src/util.d b/src/util.d index 6476fb05..8e4dc545 100644 --- a/src/util.d +++ b/src/util.d @@ -210,18 +210,30 @@ bool containsBadWhiteSpace(string path) // Check for the presence of '%0A' via regex string itemName = encodeComponent(baseName(path)); - auto invalidWhitespaceReg = ctRegex!( // Check for \n which is %0A when encoded `%0A` ); auto m = match(itemName, invalidWhitespaceReg); - return m.empty; - } +bool containsASCIIHTMLCodes(string path) +{ + // https://github.com/abraunegg/onedrive/issues/151 + // If a filename contains ASCII HTML codes, regardless of if it gets encoded, it generates an error + // Check if the filename contains an ASCII HTML code sequence + + auto invalidASCIICode = + ctRegex!( + // Check to see if &#XXXX is in the filename + `(?:&#|&#[0-9][0-9]|&#[0-9][0-9][0-9]|&#[0-9][0-9][0-9][0-9])` + ); + + auto m = match(path, invalidASCIICode); + return m.empty; +} unittest {