Bug 1262648 - Make ENTITY matching regexp allow multiline string values in browser_misused_characters_in_strings.js. r=jaws draft
authorNihanth Subramanya <nhnt11@gmail.com>
Wed, 06 Apr 2016 19:41:42 -0700
changeset 350117 990efc0cbb9f46ac75fb6bfe09c5225e574eb9aa
parent 350116 c9369050bd736b67e8833033c6e27cef00090b8e
child 518257 d29b0ae4492e4a3f3d8c1bb618284ebbfae8e8a3
push id15255
push usernhnt11@gmail.com
push dateTue, 12 Apr 2016 22:35:42 +0000
reviewersjaws
bugs1262648
milestone48.0a1
Bug 1262648 - Make ENTITY matching regexp allow multiline string values in browser_misused_characters_in_strings.js. r=jaws MozReview-Commit-ID: Hk8beXA9fjZ
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_misused_characters_in_strings.js
browser/base/content/test/general/bug1262648_string_with_newlines.dtd
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -16,16 +16,17 @@ support-files =
   browser_fxa_oauth.html
   browser_fxa_oauth_with_keys.html
   browser_fxa_web_channel.html
   browser_registerProtocolHandler_notification.html
   browser_star_hsts.sjs
   browser_tab_dragdrop2_frame1.xul
   browser_web_channel.html
   browser_web_channel_iframe.html
+  bug1262648_string_with_newlines.dtd
   bug592338.html
   bug792517-2.html
   bug792517.html
   bug792517.sjs
   bug839103.css
   contextmenu_common.js
   ctxmenu-image.png
   discovery.html
--- a/browser/base/content/test/general/browser_misused_characters_in_strings.js
+++ b/browser/base/content/test/general/browser_misused_characters_in_strings.js
@@ -122,26 +122,39 @@ add_task(function* checkAllTheProperties
     let bundle = new StringBundle(uri.spec);
     let entities = bundle.getAll();
     for (let entity of entities) {
       testForErrors(uri.spec, entity.key, entity.value);
     }
   }
 });
 
+var checkDTD = Task.async(function* (aURISpec) {
+  let rawContents = yield fetchFile(aURISpec);
+  // The regular expression below is adapted from:
+  // https://hg.mozilla.org/mozilla-central/file/68c0b7d6f16ce5bb023e08050102b5f2fe4aacd8/python/compare-locales/compare_locales/parser.py#l233
+  let entities = rawContents.match(/<!ENTITY\s+([\w\.]*)\s+("[^"]*"|'[^']*')\s*>/g);
+  for (let entity of entities) {
+    let [, key, str] = entity.match(/<!ENTITY\s+([\w\.]*)\s+("[^"]*"|'[^']*')\s*>/);
+    // The matched string includes the enclosing quotation marks,
+    // we need to slice them off.
+    str = str.slice(1, -1);
+    testForErrors(aURISpec, key, str);
+  }
+});
+
 add_task(function* checkAllTheDTDs() {
   let appDir = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
   let uris = yield generateURIsFromDirTree(appDir, [".dtd"]);
   ok(uris.length, `Found ${uris.length} .dtd files to scan for misused characters`);
+  for (let uri of uris) {
+    yield checkDTD(uri.spec);
+  }
 
-  for (let uri of uris) {
-    let rawContents = yield fetchFile(uri.spec);
-    let entities = rawContents.match(/ENTITY\s+([\w\.]*)\s+["'](.*)["']/g);
-    for (let entity of entities) {
-      let [, key, str] = entity.match(/ENTITY\s+([\w\.]*)\s+["'](.*)["']/);
-      testForErrors(uri.spec, key, str);
-    }
-  }
+  // This support DTD file supplies a string with a newline to make sure
+  // the regex in checkDTD works correctly for that case.
+  let dtdLocation = gTestPath.replace(/\/[^\/]*$/i, "/bug1262648_string_with_newlines.dtd");
+  yield checkDTD(dtdLocation);
 });
 
 add_task(function* ensureWhiteListIsEmpty() {
   is(gWhitelist.length, 0, "No remaining whitelist entries exist");
 });
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/bug1262648_string_with_newlines.dtd
@@ -0,0 +1,3 @@
+<!ENTITY foo.bar    "This string
+contains
+newlines!">
\ No newline at end of file