Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/test/testcoreutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void TestCoreUtils::testNameValidation()
{ QStringLiteral( "-project" ), true },
{ QStringLiteral( "proj_ect" ), true },
{ QStringLiteral( "proj.ect" ), true },
{ QStringLiteral( "proj!ect" ), true },
{ QStringLiteral( "proj!ect" ), false },

{ QStringLiteral( " project" ), false },
{ QStringLiteral( ".project" ), false },
Expand Down
24 changes: 21 additions & 3 deletions core/coreutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,27 @@ bool CoreUtils::isAuthConfigFile( const QString filePath )

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 );
QRegularExpressionMatch matchForbiddenNames = reForbiddenmNames.match( name );
return !matchForbiddenNames.hasMatch();
if ( name.length() > 255 )
return false;

// name must not start with whitespace, '^' or '.'
static QRegularExpression invalidFirstCharacterRe( R"(^[\s^\.].*$)", QRegularExpression::CaseInsensitiveOption );
if ( invalidFirstCharacterRe.match( name ).hasMatch() )
return false;

// name must not be a reserved Windows device filename (CON, PRN, AUX, NUL, COM1-9, LPT1-9)
static QRegularExpression invalidFilenameRe( R"(^CON$|^PRN$|^AUX$|^NUL$|^COM\d$|^LPT\d)", QRegularExpression::CaseInsensitiveOption );
if ( invalidFilenameRe.match( name ).hasMatch() )
return false;

// name must not be a word reserved by Mergin Maps / Lutra Consulting
static QRegularExpression reservedWordRe( R"(^support$|^helpdesk$|^merginmaps$|^lutraconsulting$|^mergin$|^lutra$|^input$|^sales$|^admin$)", QRegularExpression::CaseInsensitiveOption );
if ( reservedWordRe.match( name ).hasMatch() )
return false;

// name must contain only word characters, whitespace, '-' or '.'
static QRegularExpression validCharactersRe( R"(^[\w\s\-\.]+$)", QRegularExpression::UseUnicodePropertiesOption );
return validCharactersRe.match( name ).hasMatch();
}

QString CoreUtils::nameAbbr( const QString &name, const QString &email )
Expand Down
Loading