-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sanitize filenames with 'loadAsync'
- Loading branch information
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* global QUnit,JSZip,JSZipTestUtils,Promise */ | ||
'use strict'; | ||
|
||
QUnit.module("utils"); | ||
|
||
function resolve(path) { | ||
var parts = path.split("/"); | ||
var result = []; | ||
for (var index = 0; index < parts.length; index++) { | ||
var part = parts[index]; | ||
// Allow the first and last component to be empty for trailing slashes. | ||
if (part === "." || (part === "" && index !== 0 && index !== parts.length - 1)) { | ||
continue; | ||
} else if (part === "..") { | ||
result.pop(); | ||
} else { | ||
result.push(part); | ||
} | ||
} | ||
return result.join("/"); | ||
}; | ||
|
||
QUnit.test("Paths are resolved correctly", function (assert) { | ||
// Backslashes can be part of filenames | ||
assert.strictEqual(resolve("root\\a\\b"), "root\\a\\b"); | ||
assert.strictEqual(resolve("root/a/b"), "root/a/b"); | ||
assert.strictEqual(resolve("root/a/.."), "root"); | ||
assert.strictEqual(resolve("root/a/../b"), "root/b"); | ||
assert.strictEqual(resolve("root/a/./b"), "root/a/b"); | ||
assert.strictEqual(resolve("root/../../../"), ""); | ||
assert.strictEqual(resolve("////"), "/"); | ||
assert.strictEqual(resolve("/a/b/c"), "/a/b/c"); | ||
assert.strictEqual(resolve("a/b/c/"), "a/b/c/"); | ||
assert.strictEqual(resolve("../../../../../a"), "a"); | ||
assert.strictEqual(resolve("../app.js"), "app.js"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters