Skip to content

Commit 8252735

Browse files
Bug 1863636 - mochi tests for filename validation to prevent callers of new functions from creating bad file paths r=nshukla,gstoll
Added in mochi tests to validate that the C++ filename validation for taskbar tab shortcut paths works. Differential Revision: https://phabricator.services.mozilla.com/D199689
1 parent 2fa863b commit 8252735

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

browser/components/shell/nsWindowsShellService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,8 @@ static void ValidateFilename(nsAString& aFilename) {
14681468
return;
14691469
}
14701470

1471-
uint32_t flags = nsIMIMEService::VALIDATE_SANITIZE_ONLY;
1471+
uint32_t flags = nsIMIMEService::VALIDATE_SANITIZE_ONLY |
1472+
nsIMIMEService::VALIDATE_DONT_COLLAPSE_WHITESPACE;
14721473

14731474
nsAutoString outFilename;
14741475
mimeService->ValidateFileNameForSaving(aFilename, EmptyCString(), flags,

browser/components/shell/test/browser.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ skip-if = [
8484
"tsan", #Bug 1429950 , Bug 1583315, Bug 1696109, Bug 1701449
8585
]
8686

87+
["browser_pinning.js"]
88+
run-if = ["os == 'win'"]
89+
8790
["browser_setDefaultBrowser.js"]
8891

8992
["browser_setDefaultPDFHandler.js"]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
add_task(async function test_getTaskbarTabShortcutPath() {
7+
// no exception generated for the following
8+
ShellService.getTaskbarTabShortcutPath("working");
9+
ShellService.getTaskbarTabShortcutPath("workingPath.ink");
10+
11+
// confirm that multiple spaces aren't collapsed
12+
ShellService.getTaskbarTabShortcutPath("working path.ink");
13+
14+
const invalidFilenames = [
15+
// These are reserved characters that can't be in names
16+
"?",
17+
":",
18+
"<",
19+
">",
20+
"|",
21+
'"',
22+
"/",
23+
"*",
24+
"\t",
25+
"\r",
26+
"\n",
27+
28+
// No path manipulation allowed
29+
"..\\something",
30+
".\\something",
31+
".something",
32+
33+
// Windows doesn't allow filenames ending in period or a space
34+
"something.",
35+
"something ",
36+
37+
// The following are special reserved names
38+
"CON",
39+
"PRN",
40+
"AUX",
41+
"NUL",
42+
"COM1",
43+
"COM2",
44+
"COM3",
45+
"COM4",
46+
"COM5",
47+
"COM6",
48+
"COM7",
49+
"COM8",
50+
"COM9",
51+
"LPT1",
52+
"LPT2",
53+
"LPT3",
54+
"LPT4",
55+
"LPT5",
56+
"LPT6",
57+
"LPT7",
58+
"LPT8",
59+
"LPT9",
60+
];
61+
62+
for (const invalidFilename of invalidFilenames) {
63+
Assert.throws(
64+
() => {
65+
ShellService.getTaskbarTabShortcutPath(invalidFilename);
66+
},
67+
/NS_ERROR_FILE_INVALID_PATH/,
68+
invalidFilename +
69+
" is an invalid filename; getTaskbarTabShortcutPath should have failed with it as a parameter."
70+
);
71+
}
72+
});

0 commit comments

Comments
 (0)