From f0f31515810a27cb47f5947eb7331a2f925f24d4 Mon Sep 17 00:00:00 2001 From: Murat Yukselen Date: Thu, 5 Jan 2017 20:12:53 +0300 Subject: [PATCH 1/3] fix(regexp): handle ng-html-bind constant string and ternary form when ng-html-bind includes a constant string with ", it was not converted to double quotes. ng-html-bind ternary regex is hopefully fixed also --- src/index.js | 13 ++++++++++--- tests/expected/00_fr_FR.json | 3 ++- tests/expected/01_fr_FR.json | 3 ++- tests/expected/02_fr_FR.json | 3 ++- tests/expected/03_fr_FR.json | 3 ++- tests/expected/04_en_US.json | 1 + tests/expected/04_fr_FR.json | 3 ++- tests/expected/05_en_US.json | 3 ++- tests/expected/10_1_fr_FR.json | 3 ++- tests/expected/10_fr_FR.json | 3 ++- tests/expected/template.pot | 6 +++++- tests/fixtures/index.html | 8 ++++++-- 12 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index a153936..83933c8 100644 --- a/src/index.js +++ b/src/index.js @@ -108,9 +108,12 @@ var extractor case "JavascriptServiceSimpleQuote": case "JavascriptServiceInstantSimpleQuote": case "JavascriptFilterSimpleQuote": + translationKey = translationKey.replace(/\\\'/g, "'"); + break; case "HtmlNgBindHtml": - translationKey = translationKey.replace(/\\\'/g, "'") - break + translationKey = translationKey.replace(/\\\'/g, "'"); + translationKey = translationKey.replace(/"/g, '"'); + break; case "commentDoubleQuote": case "HtmlFilterDoubleQuote": case "JavascriptServiceDoubleQuote": @@ -146,6 +149,10 @@ var extractor } } + if (translationKey.indexOf("1/2'|translate") !== -1) { + _log.debug("MYN found", translationKey, regexName) + } + // Store the translationKey with the value into results var defaultValueByTranslationKey = function (translationKey, translationDefaultValue) { if (regexName !== "JavascriptServiceArraySimpleQuote" && @@ -185,7 +192,7 @@ var extractor HtmlDirectivePluralLast: 'translate="((?:\\\\.|[^"\\\\])*)".*angular-plural-extract="((?:\\\\.|[^"\\\\])*)"', HtmlDirectivePluralFirst: 'angular-plural-extract="((?:\\\\.|[^"\\\\])*)".*translate="((?:\\\\.|[^"\\\\])*)"', HtmlNgBindHtml: 'ng-bind-html="\\s*\'((?:\\\\.|[^\'\\\\])*)\'\\s*\\|\\s*translate(:.*?)?\\s*"', - HtmlNgBindHtmlTernary: 'ng-bind-html="\\s*([^?]*?[^:]*:[^|}]*)\\s*\\|\\s*translate(:.*?)?\\s*"', + HtmlNgBindHtmlTernary: 'ng-bind-html="\\s*([^\\"?]*?[^\\":]*:[^\\"|}]*)\\s*\\|\\s*translate(:.*?)?\\s*"', JavascriptServiceSimpleQuote: '\\$translate\\(\\s*\'((?:\\\\.|[^\'\\\\])*)\'[^\\)]*\\)', JavascriptServiceDoubleQuote: '\\$translate\\(\\s*"((?:\\\\.|[^"\\\\])*)"[^\\)]*\\)', JavascriptServiceArraySimpleQuote: '\\$translate\\((?:\\s*(\\[\\s*(?:(?:\'(?:(?:\\.|[^.*\'\\\\])*)\')\\s*,*\\s*)+\\s*\\])\\s*)\\)', diff --git a/tests/expected/00_fr_FR.json b/tests/expected/00_fr_FR.json index fc3b108..7cc68ed 100644 --- a/tests/expected/00_fr_FR.json +++ b/tests/expected/00_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "", "HtmlFilterSimpleQuoteOneTimeBinding": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/01_fr_FR.json b/tests/expected/01_fr_FR.json index 76a0f14..4a313f3 100644 --- a/tests/expected/01_fr_FR.json +++ b/tests/expected/01_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": null, "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": null, "HtmlFilterSimpleQuoteOneTimeBinding": null, - "HtmlNgBindHtml Key ' 1/1": null, + "HtmlNgBindHtml 2/2 Created with ": null, + "HtmlNgBindHtml Key ' 1/2": null, "JavascriptFilter 1/2 with var \"{name}\"": "my {name} javascript filter", "JavascriptFilter 2/2 without var": null, "JavascriptServiceArrayDoubleQuote 1/2 without var.": null, diff --git a/tests/expected/02_fr_FR.json b/tests/expected/02_fr_FR.json index 666ec47..170fbac 100644 --- a/tests/expected/02_fr_FR.json +++ b/tests/expected/02_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "", "HtmlFilterSimpleQuoteOneTimeBinding": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "my {name} javascript filter", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/03_fr_FR.json b/tests/expected/03_fr_FR.json index 67dc3eb..7944f24 100644 --- a/tests/expected/03_fr_FR.json +++ b/tests/expected/03_fr_FR.json @@ -10,7 +10,8 @@ "HtmlFilterSimpleQuote[] interp'olation [[xx]]": "", "HtmlFilterSimpleQuote[] on same line 1/2": "", "HtmlFilterSimpleQuote[] on same line 2/2": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/04_en_US.json b/tests/expected/04_en_US.json index 5c0866b..635a316 100644 --- a/tests/expected/04_en_US.json +++ b/tests/expected/04_en_US.json @@ -11,6 +11,7 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "HtmlFilterDoubleQuote{} on same line 2/2", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "HtmlFilterDoubleQuote{} {{var}}on same line 1/2", "HtmlFilterSimpleQuoteOneTimeBinding": "HtmlFilterSimpleQuoteOneTimeBinding", + "HtmlNgBindHtml 2/2 Created with ": "HtmlNgBindHtml 2/2 Created with ", "HtmlNgBindHtml Key ' 1/1": "HtmlNgBindHtml Key ' 1/1", "JavascriptFilter 1/2 with var \"{name}\"": "JavascriptFilter 1/2 with var \"{name}\"", "JavascriptFilter 2/2 without var": "JavascriptFilter 2/2 without var", diff --git a/tests/expected/04_fr_FR.json b/tests/expected/04_fr_FR.json index fc3b108..7cc68ed 100644 --- a/tests/expected/04_fr_FR.json +++ b/tests/expected/04_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "", "HtmlFilterSimpleQuoteOneTimeBinding": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/05_en_US.json b/tests/expected/05_en_US.json index c69e969..3ecdd46 100644 --- a/tests/expected/05_en_US.json +++ b/tests/expected/05_en_US.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "HtmlFilterDoubleQuote{} on same line 2/2", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "HtmlFilterDoubleQuote{} {{var}}on same line 1/2", "HtmlFilterSimpleQuoteOneTimeBinding": "HtmlFilterSimpleQuoteOneTimeBinding", - "HtmlNgBindHtml Key ' 1/1": "HtmlNgBindHtml Key ' 1/1", + "HtmlNgBindHtml 2/2 Created with ": "HtmlNgBindHtml 2/2 Created with ", + "HtmlNgBindHtml Key ' 1/2": "HtmlNgBindHtml Key ' 1/2", "JavascriptFilter 1/2 with var \"{name}\"": "JavascriptFilter 1/2 with var \"{name}\"", "JavascriptFilter 2/2 without var": "JavascriptFilter 2/2 without var", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "JavascriptServiceArrayDoubleQuote 1/2 without var.", diff --git a/tests/expected/10_1_fr_FR.json b/tests/expected/10_1_fr_FR.json index a303ec6..10e2b79 100644 --- a/tests/expected/10_1_fr_FR.json +++ b/tests/expected/10_1_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "", "HtmlFilterSimpleQuoteOneTimeBinding": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/10_fr_FR.json b/tests/expected/10_fr_FR.json index 09d40a0..420a5bb 100644 --- a/tests/expected/10_fr_FR.json +++ b/tests/expected/10_fr_FR.json @@ -11,7 +11,8 @@ "HtmlFilterDoubleQuote{} on same line 2/2": "", "HtmlFilterDoubleQuote{} {{var}}on same line 1/2": "", "HtmlFilterSimpleQuoteOneTimeBinding": "", - "HtmlNgBindHtml Key ' 1/1": "", + "HtmlNgBindHtml 2/2 Created with ": "", + "HtmlNgBindHtml Key ' 1/2": "", "JavascriptFilter 1/2 with var \"{name}\"": "", "JavascriptFilter 2/2 without var": "", "JavascriptServiceArrayDoubleQuote 1/2 without var.": "", diff --git a/tests/expected/template.pot b/tests/expected/template.pot index bf511fb..431e2fc 100644 --- a/tests/expected/template.pot +++ b/tests/expected/template.pot @@ -81,7 +81,11 @@ msgid "HtmlFilterSimpleQuoteOneTimeBinding" msgstr "" msgctxt "" -msgid "HtmlNgBindHtml Key ' 1/1" +msgid "HtmlNgBindHtml 2/2 Created with " +msgstr "" + +msgctxt "" +msgid "HtmlNgBindHtml Key ' 1/2" msgstr "" msgctxt "" diff --git a/tests/fixtures/index.html b/tests/fixtures/index.html index 235cf00..801d223 100644 --- a/tests/fixtures/index.html +++ b/tests/fixtures/index.html @@ -69,7 +69,11 @@

Our title text

TEST CASE - ng-bind-html -->

- + +

+ +

+

+
+

Inspect 'description' attribute

+
+