mirror of
https://github.com/abraunegg/onedrive
synced 2026-03-14 14:35:46 +01:00
Fix Bug #3175: Update 'sync_list' line parsing to correctly escape characters for regex parsing (#3184)
* Fix createRegexCompatiblePath to escape characters that cause issues for regex parsing * Update 'matchSegment' to reuse 'createRegexCompatiblePath' to be consistent in regex creation
This commit is contained in:
parent
9d329bcafc
commit
519e9ffb3a
1 changed files with 15 additions and 9 deletions
|
|
@ -599,21 +599,27 @@ class ClientSideFiltering {
|
|||
}
|
||||
return depth; // No wildcard found should be '0'
|
||||
}
|
||||
|
||||
|
||||
// Create a wildcard regex compatible string based on the sync list rule
|
||||
string createRegexCompatiblePath(string regexCompatiblePath) {
|
||||
regexCompatiblePath = regexCompatiblePath.replace(".", "\\."); // Escape the dot (.) if present
|
||||
regexCompatiblePath = regexCompatiblePath.replace(" ", "\\s"); // Escape spaces if present
|
||||
regexCompatiblePath = regexCompatiblePath.replace("*", ".*"); // Replace * with '.*' to be compatible with function and to match any characters
|
||||
// Escape all special regex characters that could break regex parsing
|
||||
regexCompatiblePath = escaper(regexCompatiblePath).text;
|
||||
|
||||
// Restore wildcard (*) support with '.*' to be compatible with function and to match any characters
|
||||
regexCompatiblePath = regexCompatiblePath.replace("\\*", ".*");
|
||||
|
||||
// Ensure space matches only literal space, not \s (tabs, etc.)
|
||||
regexCompatiblePath = regexCompatiblePath.replace(" ", "\\ ");
|
||||
|
||||
// Return the regex compatible path
|
||||
return regexCompatiblePath;
|
||||
}
|
||||
|
||||
|
||||
// Create a regex compatible string to match a relevant segment
|
||||
bool matchSegment(string ruleSegment, string pathSegment) {
|
||||
ruleSegment = ruleSegment.replace("*", ".*"); // Replace * with '.*' to be compatible with function and to match any characters
|
||||
ruleSegment = ruleSegment.replace(" ", "\\s"); // Escape spaces if present
|
||||
auto pattern = regex("^" ~ ruleSegment ~ "$");
|
||||
// Check if there's a match
|
||||
// Create the required pattern
|
||||
auto pattern = regex("^" ~ createRegexCompatiblePath(ruleSegment) ~ "$");
|
||||
// Check if there's a match and return result
|
||||
return !match(pathSegment, pattern).empty;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue