Resolve crash with strange filename (Issue #151) (#178)

* Update file handling to look for HTML ASCII codes which will cause uploads to fail
This commit is contained in:
abraunegg 2018-10-04 09:33:39 +10:00 committed by GitHub
parent 31fc6a4d4f
commit 14b2de8f4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -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 != ".") {

View file

@ -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
{