Bug 1562176 - fix colons in 'save file as' filenames, r=mak

Differential Revision: https://phabricator.services.mozilla.com/D37400

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2019-07-09 19:45:10 +00:00
Родитель 64633547a3
Коммит 2579f3d685
2 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -24,6 +24,8 @@ ChromeUtils.defineModuleGetter(
* Platform-dependent regular expression used by the "sanitize" method.
*/
XPCOMUtils.defineLazyGetter(this, "gConvertToSpaceRegExp", () => {
// Note: we remove colons everywhere to avoid issues in subresource URL
// parsing, as well as filename restrictions on some OSes (see bug 1562176).
/* eslint-disable no-control-regex */
switch (AppConstants.platform) {
// On mobile devices, the file system may be very limited in what it
@ -32,10 +34,8 @@ XPCOMUtils.defineLazyGetter(this, "gConvertToSpaceRegExp", () => {
return /[\x00-\x1f\x7f-\x9f:*?|"<>;,+=\[\]]+/g;
case "win":
return /[\x00-\x1f\x7f-\x9f:*?|]+/g;
case "macosx":
return /[\x00-\x1f\x7f-\x9f:]+/g;
default:
return /[\x00-\x1f\x7f-\x9f]+/g;
return /[\x00-\x1f\x7f-\x9f:]+/g;
}
/* eslint-enable no-control-regex */
});

Просмотреть файл

@ -52,11 +52,11 @@ add_task(async function test_sanitize() {
testSanitize("Website | Page!", "Website | Page!");
testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_");
} else {
testSanitize(kSpecialChars, kSpecialChars);
testSanitize(" :: Website :: ", ":: Website ::");
testSanitize(kSpecialChars, kSpecialChars.replace(/[:]/g, " "));
testSanitize(" :: Website :: ", "Website");
testSanitize("* Website!", "* Website!");
testSanitize("Website | Page!", "Website | Page!");
testSanitize("Directory Listing: /a/b/", "Directory Listing: _a_b_");
testSanitize("Directory Listing: /a/b/", "Directory Listing _a_b_");
}
// Conversion of consecutive runs of slashes and backslashes to underscores.
@ -79,6 +79,9 @@ add_task(async function test_sanitize() {
// Stripping of BIDI formatting characters.
testSanitize("\u200e \u202b\u202c\u202d\u202etest\x7f\u200f", "test");
testSanitize("AB\x7f\u202a\x7f\u202a\x7fCD", "AB CD");
// Stripping of colons:
testSanitize("foo:bar", "foo bar");
});
add_task(async function test_splitBaseNameAndExtension() {