Remove eval() from JS code
This issue was created automatically by a script.
Bug 1311053
Bug Reporter: @mathjazz CC: [email protected] Blocker for: Bug 1338247
We use eval() in JS to calculate examples of different plural forms for each language, which is done using the plural rule (e.g. https://github.com/mozilla-l10n/input-l10n/blob/master/sl/LC_MESSAGES/django.po#L14) that we store in the DB and pass to JS in a variable, and finally run eval() on it.
We should do this only once per locale, so it can be moved to python and executed when locale is added. Currently the code lives in JS, because it uses the same ternary operator syntax as PO files.
This will also allow us to remove unsafe-eval from CSP.
Comment Author: @psiinon
+1 for this :)
Comment Author: GitHub Bugzilla PR Linker <[email protected]>
Created attachment 8925541 Link to GitHub pull-request: https://github.com/mozilla/pontoon/pull/748
Attached file: file_150881901.txt (text/x-github-pull-request, 43 bytes) Description: Link to GitHub pull-request: https://github.com/mozilla/pontoon/pull/748
Comment Author: @github-actions
Commit pushed to master at https://github.com/mozilla/pontoon
https://github.com/mozilla/pontoon/commit/8c5c722c63334f53f29618af0307b181b9bfa420 Bug #1311053: Always assign plural examples (#748)
For each plural form of a locale, we calculate example number to use as a hint in the UI. Examples were not assigned to locales with 2 plural forms prior to this fix.
Comment Author: [email protected]
Hi @mathjazz this bug seems interesting to me how can I proceed for this Can I provide the solution without assigning it?
Comment Author: @mathjazz
Akshjain, a mentored bug like bug #1604038 would be a better first bug. Would you like me to assign it to you?
This bug requires slightly more work, so it could be a good 2nd bug. :)
Comment Author: [email protected]
Okay @mathjazz I would love to work on 2nd bug which you referred to me . Please assign it to me Thanks
This has been fixed for quite a while now.
Actually, that's wrong; we don't use eval(), but we do use new Function() for this: https://github.com/mozilla/pontoon/blob/a0d0d9ab740cec8e837adbe28d4b8b7c25a08c64/translate/src/hooks/usePluralExamples.ts#L25-L26