mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-03 04:39:12 +00:00
Test path manipulation methods sanitise correctly
There's some nuance here with pattern vs non-pattern characters, so useful to test for that.
This commit is contained in:
parent
e57b6fede2
commit
80c7a54ad4
@ -101,7 +101,7 @@ public class FSAPI implements ILuaAPI {
|
|||||||
* }</pre>
|
* }</pre>
|
||||||
*/
|
*/
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public final String[] list(String path) throws LuaException {
|
public final List<String> list(String path) throws LuaException {
|
||||||
try (var ignored = environment.time(Metrics.FS_OPS)) {
|
try (var ignored = environment.time(Metrics.FS_OPS)) {
|
||||||
return getFileSystem().list(path);
|
return getFileSystem().list(path);
|
||||||
} catch (FileSystemException e) {
|
} catch (FileSystemException e) {
|
||||||
|
@ -149,7 +149,7 @@ public class FileSystem {
|
|||||||
return getMount(sanitizePath(path)).getAttributes(sanitizePath(path));
|
return getMount(sanitizePath(path)).getAttributes(sanitizePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String[] list(String path) throws FileSystemException {
|
public synchronized List<String> list(String path) throws FileSystemException {
|
||||||
path = sanitizePath(path);
|
path = sanitizePath(path);
|
||||||
var mount = getMount(path);
|
var mount = getMount(path);
|
||||||
|
|
||||||
@ -165,10 +165,8 @@ public class FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return list
|
// Return list
|
||||||
var array = new String[list.size()];
|
list.sort(Comparator.naturalOrder());
|
||||||
list.toArray(array);
|
return list;
|
||||||
Arrays.sort(array);
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean exists(String path) throws FileSystemException {
|
public synchronized boolean exists(String path) throws FileSystemException {
|
||||||
|
@ -158,6 +158,14 @@ describe("The fs library", function()
|
|||||||
expect(fs.combine("", "a")):eq("a")
|
expect(fs.combine("", "a")):eq("a")
|
||||||
expect(fs.combine("a", "", "b", "c")):eq("a/b/c")
|
expect(fs.combine("a", "", "b", "c")):eq("a/b/c")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("preserves pattern characters", function()
|
||||||
|
expect(fs.combine("foo*?")):eq("foo*?")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("sanitises paths", function()
|
||||||
|
expect(fs.combine("foo\":<>|")):eq("foo")
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("fs.getName", function()
|
describe("fs.getName", function()
|
||||||
@ -175,6 +183,14 @@ describe("The fs library", function()
|
|||||||
it("returns '..' for parent directories", function()
|
it("returns '..' for parent directories", function()
|
||||||
expect(fs.getName("..")):eq("..")
|
expect(fs.getName("..")):eq("..")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("preserves pattern characters", function()
|
||||||
|
expect(fs.getName("foo*?")):eq("foo*?")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("sanitises paths", function()
|
||||||
|
expect(fs.getName("foo\":<>|")):eq("foo")
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("fs.getDir", function()
|
describe("fs.getDir", function()
|
||||||
@ -193,6 +209,14 @@ describe("The fs library", function()
|
|||||||
expect(fs.getDir("..")):eq("../..")
|
expect(fs.getDir("..")):eq("../..")
|
||||||
expect(fs.getDir("../..")):eq("../../..")
|
expect(fs.getDir("../..")):eq("../../..")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("preserves pattern characters", function()
|
||||||
|
expect(fs.getDir("foo*?/x")):eq("foo*?")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("sanitises paths", function()
|
||||||
|
expect(fs.getDir("foo\":<>|/x")):eq("foo")
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("fs.getSize", function()
|
describe("fs.getSize", function()
|
||||||
|
Loading…
Reference in New Issue
Block a user