Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve name validation #13574

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 5 additions & 15 deletions classes/Validate.php
Expand Up @@ -157,21 +157,11 @@ public static function isImageSize($size)
*/
public static function isName($name)
{
$cleanName = stripslashes($name);
// disallow content that looks like an url - slash character
if (false !== strpos($cleanName, '/')) {
return 0;
}
// disallow content that looks like an url - dots character
$dotCharacters = array('.', '。');
foreach ($dotCharacters as $dotCharacter) {
$dotPosition = strpos($cleanName, $dotCharacter);
if (false !== $dotPosition && isset($cleanName[$dotPosition + 1]) && ($cleanName[$dotPosition + 1] !== ' ')) {
return 0;
}
}
$validityPattern = Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:¤|]*$/u');
return preg_match($validityPattern, $cleanName);
$validityPattern = Tools::cleanNonUnicodeSupport(
'/^(?:[^0-9!<>,;?=+()\/\\@#"°*`{}_^$%:¤|\.。]|[\.。](?:\s|$))*$/u'
);

return preg_match($validityPattern, $name);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion tests/Unit/classes/ValidateCoreTest.php
Expand Up @@ -114,7 +114,7 @@ public function testIsInt($expected, $input)
{
$this->assertSame($expected, Validate::isInt($input));
}

// --- providers ---

public function isIp2LongDataProvider()
Expand Down Expand Up @@ -155,11 +155,21 @@ public function isNameDataProvider()
array(1, 'Mathieu'),
array(1, 'Dupont'),
array(1, 'Jaçinthé'),
array(1, 'Jaçinthø'),
array(1, 'John D.'),
array(1, 'John D. John'),
array(1, 'John D. John D.'),
array(1, 'Mario Bros.'),
array(1, 'ââââ'),
array(0, 'https://www.website.com'),
array(0, 'www.website.com'),
array(0, 'www\.website\.com'),
array(0, 'www\\.website\\.com'),
array(0, 'www.website.com.'),
array(0, 'website。com'),
array(0, 'John D. www.some.site'),
array(0, 'www.website.com is cool'),
array(0, 'website。com。'),
array(0, 'website。com'),
array(0, 'website%2Ecom'),
array(0, 'website/./com'),
Expand Down