boardpack/pydantic-i18n

Translation strings cannot have any special-characters used in regular expressions

Closed this issue · 0 comments

Describe the bug

If the input string for a translation contains a character with special meaning in regular expressions (e.g., [), this usually breaks the import of the translations. If the string happens to be a valid regular expression, it breaks matching of the text to translate.

To Reproduce

Steps to reproduce the behavior:

  1. Create a translation containing [ inside the text
  2. Load the translations
  3. Loader crashes

Steps to reproduce the behavior (alternative):

  1. Create a translation containing a valid regexp expression [a] inside the text
  2. Load translations
  3. Attempt to translate a string
  4. Translation lookup fails, returning un-translated string

Environment

  • OS: [e.g. Linux / Windows / macOS]: any
  • pydantic-i18n version: current main (e.g., 0.4.0)

To know the pydantic-i18n version use:

python -c "import pydantic_i18n; print(pydantic_i18n.__version__)"
  • Python version:

any (e.g., 3.11.8)

Additional context

Will submit a pull-request shortly