Bug 1262648 - Make ENTITY matching regexp allow multiline string values in browser_misused_characters_in_strings.js. r=jaws
MozReview-Commit-ID: Hk8beXA9fjZ
--- 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