Skip to content

Commit 47d61e0

Browse files
committed
Add test for File.startsWith
1 parent 71a6b09 commit 47d61e0

File tree

1 file changed

+23
-1
lines changed
  • java/ql/test/library-tests/pathsanitizer

1 file changed

+23
-1
lines changed

java/ql/test/library-tests/pathsanitizer/TestKt.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ class TestKt {
106106
}
107107
run {
108108
val source: File? = source() as File?
109-
val normalized: File = source!!.canonicalFile.toString()
109+
val normalized: File = source!!.canonicalFile
110+
if (normalized.startsWith("/safe")) {
111+
sink(source) // Safe
112+
sink(normalized) // Safe
113+
} else {
114+
sink(source) // $ hasTaintFlow
115+
sink(normalized) // $ hasTaintFlow
116+
}
117+
}
118+
run {
119+
val source: File? = source() as File?
120+
val normalized: String = source!!.canonicalFile.toString()
110121
if (normalized.startsWith("/safe")) {
111122
sink(source) // Safe
112123
sink(normalized) // Safe
@@ -337,6 +348,17 @@ class TestKt {
337348
sink(normalized) // $ hasTaintFlow
338349
}
339350
}
351+
run {
352+
val source: File? = source() as File?
353+
val normalized: File = source!!.canonicalFile
354+
if (!normalized.startsWith("/data")) {
355+
sink(source) // Safe
356+
sink(normalized) // Safe
357+
} else {
358+
sink(source) // $ hasTaintFlow
359+
sink(normalized) // $ hasTaintFlow
360+
}
361+
}
340362
run {
341363
val source: File? = source() as File?
342364
val normalized: String = source!!.canonicalFile.toString()

0 commit comments

Comments
 (0)