From 35ebdc87d4ecbcc98550e576e3aeb91b9cc18be7 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 25 Mar 2024 09:33:01 +1100 Subject: [PATCH] Update regular expression for invalid patterns * Update regular expression for invalid patterns for efficiency * Update table title --- docs/usage.md | 2 +- src/util.d | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 2ee6028c..31636993 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -103,7 +103,7 @@ Should a file or folder infringe upon these naming conventions or restrictions, > [!TIP] > UTF-16 provides a capability to use UTF-16 characters to work around the restrictions and limitations imposed by Microsoft OneDrive. An example of some replacement characters are below: -> | Standard Character | UTF-16 Replacement Character | +> | Standard Invalid Character | Potential UTF-16 Replacement Character | > |--------------------|------------------------------| > | . | ․ (One Dot Leader, `\u2024`) | > | : | ː (Modifier Letter Triangular Colon, `\u02D0`) | diff --git a/src/util.d b/src/util.d index 56d1d7e7..cb6515de 100644 --- a/src/util.d +++ b/src/util.d @@ -350,11 +350,18 @@ bool isValidName(string path) { // Regular expression for invalid patterns // https://support.microsoft.com/en-us/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa?ui=en-us&rs=en-us&ad=us#invalidcharacters - // Leading whitespace and trailing whitespace/dot + // Leading whitespace and trailing whitespace // Invalid characters - auto invalidNameReg = ctRegex!(`^\s.*|^.*[\s\.]$|.*[<>:"\|\?*/\\].*`); + // Trailing dot '.' (not documented above) , however see issue https://github.com/abraunegg/onedrive/issues/2678 - auto matchResult = match(itemName, invalidNameReg); + //auto invalidNameReg = ctRegex!(`^\s.*|^.*[\s\.]$|.*[<>:"\|\?*/\\].*`); - original to remove at some point + auto invalidNameReg = ctRegex!(`^\s+|\s$|\.$|[<>:"\|\?*/\\]`); // revised 25/3/2024 + // - ^\s+ matches one or more whitespace characters at the start of the string. The + ensures we match one or more whitespaces, making it more efficient than .* for detecting leading whitespaces. + // - \s$ matches a whitespace character at the end of the string. This is more precise than [\s\.]$ because we'll handle the dot separately. + // - \.$ specifically matches a dot character at the end of the string, addressing the requirement to catch trailing dots as invalid. + // - [<>:"\|\?*/\\] matches any single instance of the specified invalid characters: ", *, :, <, >, ?, /, \, | + + auto matchResult = match(itemName, invalidNameReg); if (!matchResult.empty) { return false; }