-
Problem report
-
Resolution: Fixed
-
Minor
-
4.0.0alpha6
-
Sprint 46, Nov 2018, Sprint 47, Dec 2018
-
0.5
Steps to reproduce:
- Go to Administration→General
- Select Icon mapping
- Click Create icon map
- Enter some silly Name
- Enter / in Expression field
- Click Add button
Result:
See invalid_regular_expression.png
Cannot create icon map
Invalid parameter "/1/mappings/1/expression": invalid regular expression. [adm.iconmapping.php:70 ? CApiWrapper->__call() ? CFrontendApiWrapper->callMethod() ? CApiWrapper->callMethod() ? CFrontendApiWrapper->callClientMethod() ? CLocalApiClient->callMethod() ? CIconMap->create() ? CIconMap->validateCreate() ? CApiService::exception() in include/classes/api/services/CIconMap.php:192]
Expected:
Icon map is successfully created because / is a valid regular expression (check it here), forward slash is not a special character.
Comments:
Even though forward slash is not a special character it needs to be escaped in the pattern if forward slash is also used as delimiter (which is a very common practice). Unfortunately, preg_quote() cannot be used here because we don't want to escape special characters user wants to provide in his/her pattern. The best approach would probably be to surround user pattern with parentheses, brackets or braces as suggested in this wonderful article.