WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.63k stars 1.02k forks source link

Regex flag have an unexpected behavior #4482

Closed Heziode closed 4 years ago

Heziode commented 4 years ago

Describe the bug

Regex flag do not capture the last character when it is a closing parenthesis. Regex flag do not capture well pattern inside { and }.

To Reproduce

Steps to reproduce the behavior:

I add this regex flag: regex:"((?:@:\(|\{)[^\)\}]+(?:\)|\}))" Testing string: @:(foo.bar.baz) | @:(hello.world) | {foo32} Check on regex101: https://regex101.com/r/SZVYGO/1

Expected behavior

Regex flag do capture the last character when it is a closing parenthesis. Regex flag do capture well pattern inside { and }.

Screenshots

2020-09-10 13 17 16 translate foe tools 036dda149824

Server configuration and status

docker-compose exec weblate weblate list_versions:

Weblate deploy checks

docker-compose exec --user weblate weblate weblate check --deploy:

SystemCheckError: System check identified some issues:

CRITICALS:
?: (weblate.E003) Cannot send e-mail ([Errno -2] Name or service not known), please check EMAIL_* settings.
    HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#out-mail

WARNINGS:
?: (security.W005) You have not set the SECURE_HSTS_INCLUDE_SUBDOMAINS setting to True. Without this, your site is potentially vulnerable to attack via an insecure connection to a subdomain. Only set this to True if you are certain that all subdomains of your domain should be served exclusively via SSL.

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
    HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
    HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/backup.html
?: (weblate.I031) New Weblate version is available, please upgrade to 4.2.2.
    HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/upgrade.html

System check identified 5 issues (1 silenced).
nijel commented 4 years ago

The problem here is that flag parsing handles escape sequences as well, so your expression is parsed as: ((?:@:(|{)[^)}]+(?:)|}))

This matches exactly what you observe: https://regex101.com/r/O9zVx5/1

Such behavior is probably not desired, I will look whether it's possible to address this (especially whether something else relies in this behavior).

Heziode commented 4 years ago

The problem here is that flag parsing handles escape sequences as well, so your expression is parsed as: ((?:@:(|{)[^)}]+(?:)|}))

Exact !

Furthermore, it's planed to add regex support for placeholders ?

nijel commented 4 years ago

Furthermore, it's planed to add regex support for placeholders ?

No, feel free to create separate issue for that.

github-actions[bot] commented 4 years ago

The issue you have reported seems to be resolved now.