Skip to content

Commit

Permalink
Merge pull request #81 from guillaumepotier/fix-cve
Browse files Browse the repository at this point in the history
Fix valid plural regex check
  • Loading branch information
guillaumepotier authored Aug 14, 2024
2 parents c5a587c + 6e52e0f commit 8150aeb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 9 deletions.
6 changes: 5 additions & 1 deletion dist/gettext.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ define(function () { 'use strict';
// plural forms list available here http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
var pf_re = new RegExp('^\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;n0-9_\(\)])+');

if (!pf_re.test(plural_form))
var match = plural_form.match(pf_re);

if (!match || match[0] !== plural_form)
throw new Error(strfmt('The plural form "%1" is not valid', plural_form));

console.log('>>> Plural form:', plural_form);

// Careful here, this is a hidden eval() equivalent..
// Risk should be reasonable though since we test the plural_form through regex before
// taken from https://github.com/Orange-OpenSource/gettext.js/blob/master/lib.gettext.js
Expand Down
2 changes: 1 addition & 1 deletion dist/gettext.amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dist/gettext.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ var i18n = function (options) {
// plural forms list available here http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
var pf_re = new RegExp('^\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;n0-9_\(\)])+');

if (!pf_re.test(plural_form))
var match = plural_form.match(pf_re);

if (!match || match[0] !== plural_form)
throw new Error(strfmt('The plural form "%1" is not valid', plural_form));

console.log('>>> Plural form:', plural_form);

// Careful here, this is a hidden eval() equivalent..
// Risk should be reasonable though since we test the plural_form through regex before
// taken from https://github.com/Orange-OpenSource/gettext.js/blob/master/lib.gettext.js
Expand Down
2 changes: 1 addition & 1 deletion dist/gettext.cjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dist/gettext.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ var i18n = function (options) {
// plural forms list available here http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
var pf_re = new RegExp('^\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;n0-9_\(\)])+');

if (!pf_re.test(plural_form))
var match = plural_form.match(pf_re);

if (!match || match[0] !== plural_form)
throw new Error(strfmt('The plural form "%1" is not valid', plural_form));

console.log('>>> Plural form:', plural_form);

// Careful here, this is a hidden eval() equivalent..
// Risk should be reasonable though since we test the plural_form through regex before
// taken from https://github.com/Orange-OpenSource/gettext.js/blob/master/lib.gettext.js
Expand Down
Loading

0 comments on commit 8150aeb

Please # to comment.