Align mobile regex with server regex#4590
Conversation
📦 Build Artifacts Ready
|
| bool CoreUtils::isValidName( const QString &name ) | ||
| { | ||
| static QRegularExpression reForbiddenmNames( R"([@#$%^&*\(\)\{\}\[\]\\\/\|\+=<>~\?:;,`\'\"]|^[\s^\.].*$|^CON$|^PRN$|^AUX$|^NUL$|^COM\d$|^LPT\d|^support$|^helpdesk$|^merginmaps$|^lutraconsulting$|^mergin$|^lutra$|^input$|^sales$|^admin$)", QRegularExpression::CaseInsensitiveOption ); | ||
| static QRegularExpression reForbiddenmNames( R"(^[\s^\.].*$|^CON$|^PRN$|^AUX$|^NUL$|^COM\d$|^LPT\d|^support$|^helpdesk$|^merginmaps$|^lutraconsulting$|^mergin$|^lutra$|^input$|^sales$|^admin$)", QRegularExpression::CaseInsensitiveOption ); |
There was a problem hiding this comment.
Could you split this long regex to multiple by category as server does?
| return !matchForbiddenNames.hasMatch(); | ||
| QRegularExpressionMatch matchValidCharacters = reValidCharacters.match( name ); | ||
|
|
||
| return !matchForbiddenNames.hasMatch() && matchValidCharacters.hasMatch(); |
There was a problem hiding this comment.
We should check the length of the file name, maximum 255 dictated by pathvalidate lib
📦 Build Artifacts Ready
|
Withalion
left a comment
There was a problem hiding this comment.
What about those tests?
| static bool hasValidFirstCharacter( const QString &name ) | ||
| { | ||
| static QRegularExpression re( R"(^[\s^\.].*$)", QRegularExpression::CaseInsensitiveOption ); | ||
| return !re.match( name ).hasMatch(); | ||
| } | ||
|
|
||
| static bool isInvalidFilename( const QString &name ) | ||
| { | ||
| if ( name.length() > 255 ) | ||
| return true; | ||
|
|
||
| static QRegularExpression re( R"(^CON$|^PRN$|^AUX$|^NUL$|^COM\d$|^LPT\d)", QRegularExpression::CaseInsensitiveOption ); | ||
| return re.match( name ).hasMatch(); | ||
| } | ||
|
|
||
| static bool isReservedWord( const QString &name ) | ||
| { | ||
| static QRegularExpression re( R"(^support$|^helpdesk$|^merginmaps$|^lutraconsulting$|^mergin$|^lutra$|^input$|^sales$|^admin$)", QRegularExpression::CaseInsensitiveOption ); | ||
| return re.match( name ).hasMatch(); | ||
| } | ||
|
|
||
| static bool hasValidCharacters( const QString &name ) | ||
| { | ||
| static QRegularExpression re( R"(^[\w\s\-\.]+$)" ); | ||
| return re.match( name ).hasMatch(); | ||
| } |
There was a problem hiding this comment.
no need to create new functions, just bundle all the regexes in isValidName()
also you are missing function declarations of these new functions in header file if they would stay
There was a problem hiding this comment.
Totally forgot there are tests. On it
📦 Build Artifacts Ready
|
Coverage Report for CI Build 29826232857Warning No base build found for commit Coverage: 59.066%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
📦 Build Artifacts Ready
|
📦 Build Artifacts Ready
|
Description
Aligns the mobile app project name validation with the server validation rules. Previously, the mobile app used a different (blacklist-based) character validation than the server (whitelist-based), which allowed users to create local projects with names containing characters the server would reject - meaning the project could never be pushed/synced because some characters were missing from the mobile regex.
Tickets: #4516, #4365
Current behaviour
The mobile app only blocked a fixed set of blacklisted special characters (
@#$%^&*(){}[]\/|+=<>~?:;,`'"etc.). Any character not explicitly listed was allowed, even if the server would reject it later.This meant a user could successfully create a local project with an invalid name (e.g. containing
!), work with it locally, and only discover the mismatch when sync to the server failed.What changed
reForbiddenNamesinCoreUtils::isValidName()reValidCharacters, allowing only word characters, whitespace, hyphens, and dots (^[\w\s\-\.]+$) — matching the server'shas_valid_characters()checkisValidName()now requires both checks to pass: the name must not match any forbidden pattern (reserved words, OS device names, leading space/dot) and must match the valid-character whitelistExpected behaviour
Project names can now only contain characters the server also accepts, preventing the local-creation/server-rejection mismatch
Previously problematic characters like
'or!are now handled consistently - screenshot attached showing project creation working correctly with these characters