Bug 1262648 - Make ENTITY matching regexp allow multiline string values in browser_misused_characters_in_strings.js. r=jaws
authorNihanth Subramanya <nhnt11@gmail.com>
Wed, 06 Apr 2016 19:41:42 -0700
changeset 331995 5ad0f8d2d7dffcf57ff4d935f5dfb4781683091e
parent 331994 c277eb72ddb0eafcc8068d9dd38a341a45d0155b
child 331996 fed6d478bf3d7cc80fbcf975361a2e2bc8e4ed30
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1262648
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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