mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-23 15:36:54 +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>
|
||||
*/
|
||||
@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)) {
|
||||
return getFileSystem().list(path);
|
||||
} catch (FileSystemException e) {
|
||||
|
@ -149,7 +149,7 @@ public class FileSystem {
|
||||
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);
|
||||
var mount = getMount(path);
|
||||
|
||||
@ -165,10 +165,8 @@ public class FileSystem {
|
||||
}
|
||||
|
||||
// Return list
|
||||
var array = new String[list.size()];
|
||||
list.toArray(array);
|
||||
Arrays.sort(array);
|
||||
return array;
|
||||
list.sort(Comparator.naturalOrder());
|
||||
return list;
|
||||
}
|
||||
|
||||
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", "", "b", "c")):eq("a/b/c")
|
||||
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)
|
||||
|
||||
describe("fs.getName", function()
|
||||
@ -175,6 +183,14 @@ describe("The fs library", function()
|
||||
it("returns '..' for parent directories", function()
|
||||
expect(fs.getName("..")):eq("..")
|
||||
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)
|
||||
|
||||
describe("fs.getDir", function()
|
||||
@ -193,6 +209,14 @@ describe("The fs library", function()
|
||||
expect(fs.getDir("..")):eq("../..")
|
||||
expect(fs.getDir("../..")):eq("../../..")
|
||||
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)
|
||||
|
||||
describe("fs.getSize", function()
|
||||
|
Loading…
Reference in New Issue
Block a user