Fix 'sync_list' path handling for sub item matching (#1317)

* Fix 'sync_list' path handling for sub item matching, so that items in parent are not implicitly matched when there is no wildcard present
This commit is contained in:
abraunegg 2021-03-05 09:15:44 +11:00 committed by GitHub
parent 81e40ba76d
commit f107427480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -275,7 +275,7 @@ private bool isPathExcluded(string path, string[] allowedPaths)
// Generate the common prefix from the path vs the allowed path // Generate the common prefix from the path vs the allowed path
auto comm = commonPrefix(path, allowedPath[offset..$]); auto comm = commonPrefix(path, allowedPath[offset..$]);
// is path is an exact match of the allowed path // Is path is an exact match of the allowed path?
if (comm.length == path.length) { if (comm.length == path.length) {
// the given path is contained in an allowed path // the given path is contained in an allowed path
if (!exclude) { if (!exclude) {
@ -290,22 +290,28 @@ private bool isPathExcluded(string path, string[] allowedPaths)
} }
} }
// is path is a subitem of the allowed path // Is path is a subitem/sub-folder of the allowed path?
if (comm.length == allowedPath[offset..$].length) { if (comm.length == allowedPath[offset..$].length) {
// the given path is a subitem of an allowed path // The given path is potentially a subitem of an allowed path
if (!exclude) { // We want to capture sub-folders / files of allowed paths here, but not explicitly match other items
log.vdebug("Evaluation against 'sync_list' result: parental path match"); // if there is no wildcard
finalResult = false; auto subItemPathCheck = allowedPath[offset..$] ~ "/";
// parental path matches, break and go sync if (canFind(path, subItemPathCheck)) {
break; // The 'path' includes the allowed path, and is 'most likely' a sub-path item
} else { if (!exclude) {
log.vdebug("Evaluation against 'sync_list' result: parental path match but must be excluded"); log.vdebug("Evaluation against 'sync_list' result: parental path match");
finalResult = true; finalResult = false;
excludeMatched = true; // parental path matches, break and go sync
break;
} else {
log.vdebug("Evaluation against 'sync_list' result: parental path match but must be excluded");
finalResult = true;
excludeMatched = true;
}
} }
} }
// does the allowed path contain a wildcard? (*) // Does the allowed path contain a wildcard? (*)
if (canFind(allowedPath[offset..$], wildcard)) { if (canFind(allowedPath[offset..$], wildcard)) {
// allowed path contains a wildcard // allowed path contains a wildcard
// manually replace '*' for '.*' to be compatible with regex // manually replace '*' for '.*' to be compatible with regex