Skip to content

Commit 88c7a22

Browse files
authored
Merge branch 'main' into empty-dir-zip
2 parents a02fbab + 8d4bf10 commit 88c7a22

File tree

4 files changed

+77
-30
lines changed

4 files changed

+77
-30
lines changed

os/src/Path.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ object PathChunk extends PathChunkMacros {
2626
val splitted = strNoTrailingSeps.split('/')
2727
splitted ++ Array.fill(trailingSeparatorsCount)("")
2828
}
29-
29+
private def reduceUps(in: Array[String]): List[String] =
30+
in.foldLeft(List.empty[String]) { case (acc, x) =>
31+
acc match {
32+
case h :: t if h == ".." => x :: acc
33+
case h :: t if x == ".." => t
34+
case _ => x :: acc
35+
}
36+
}.reverse
3037
private[os] def segmentsFromStringLiteralValidation(literal: String): Array[String] = {
3138
val stringSegments = segmentsFromString(literal)
32-
val validSegmnts = validLiteralSegments(stringSegments)
39+
val validSegmnts = reduceUps(validLiteralSegments(stringSegments))
3340
val sanitizedLiteral = validSegmnts.mkString("/")
3441
if (validSegmnts.isEmpty) throw InvalidSegment(
3542
literal,

os/test/src-jvm/ExpectyIntegration.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ object ExpectyIntegration extends TestSuite {
1414
}
1515
test("literals with [..]") {
1616
expect(rel / "src" / ".." == rel / "src" / os.up)
17-
expect(root / "src/.." == root / "src" / os.up)
1817
expect(root / "src" / ".." == root / "src" / os.up)
1918
expect(root / "hello" / ".." / "world" == root / "hello" / os.up / "world")
2019
expect(root / "hello" / "../world" == root / "hello" / os.up / "world")
21-
expect(root / "hello/../world" == root / "hello" / os.up / "world")
2220
}
2321
test("from issue") {
2422
expect(Seq(os.pwd / "foo") == Seq(os.pwd / "foo"))
2523
val path = os.Path("/") / "tmp" / "foo"
2624
expect(path.startsWith(os.Path("/") / "tmp"))
2725
}
2826
test("multiple args") {
29-
expect(rel / "src" / ".." == rel / "src" / os.up, root / "src/.." == root / "src" / os.up)
27+
expect(
28+
rel / "src" / ".." == rel / "src" / os.up,
29+
root / "src" / "../foo" == root / "src" / os.up / "foo"
30+
)
3031
}
3132
}
3233
}

os/test/src/PathTests.scala

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,52 @@ object PathTests extends TestSuite {
2323
test("literals with [..]") {
2424

2525
assert(rel / "src" / ".." == rel / "src" / os.up)
26-
assert(root / "src/.." == root / "src" / os.up)
2726
assert(root / "src" / ".." == root / "src" / os.up)
2827
assert(root / "hello" / ".." / "world" == root / "hello" / os.up / "world")
2928
assert(root / "hello" / "../world" == root / "hello" / os.up / "world")
30-
assert(root / "hello/../world" == root / "hello" / os.up / "world")
3129
}
3230

3331
test("Compile errors") {
32+
33+
compileError("""root / "src/../foo"""").check("", nonCanonicalLiteral("src/../foo", "foo"))
34+
compileError("""root / "hello/../world"""").check(
35+
"",
36+
nonCanonicalLiteral("hello/../world", "world")
37+
)
38+
compileError("""root / "src/../foo/bar"""").check(
39+
"",
40+
nonCanonicalLiteral("src/../foo/bar", "foo/bar")
41+
)
42+
compileError("""root / "src/../foo/bar/.."""").check(
43+
"",
44+
nonCanonicalLiteral("src/../foo/bar/..", "foo")
45+
)
46+
compileError("""root / "src/../foo/../bar/."""").check(
47+
"",
48+
nonCanonicalLiteral("src/../foo/../bar/.", "bar")
49+
)
50+
compileError("""root / "src/foo/./.."""").check(
51+
"",
52+
nonCanonicalLiteral("src/foo/./..", "src")
53+
)
54+
compileError("""root / "src/foo//./.."""").check(
55+
"",
56+
nonCanonicalLiteral("src/foo//./..", "src")
57+
)
58+
59+
compileError("""root / "src/.."""").check("", removeLiteralErr("src/.."))
60+
compileError("""root / "src/../foo/.."""").check("", removeLiteralErr("src/../foo/.."))
61+
compileError("""root / "src/foo/../.."""").check("", removeLiteralErr("src/foo/../.."))
62+
compileError("""root / "src/foo/./../.."""").check("", removeLiteralErr("src/foo/./../.."))
63+
compileError("""root / "src/./foo/./../.."""").check(
64+
"",
65+
removeLiteralErr("src/./foo/./../..")
66+
)
67+
compileError("""root / "src///foo/./../.."""").check(
68+
"",
69+
removeLiteralErr("src///foo/./../..")
70+
)
71+
3472
compileError("""root / "/" """).check("", removeLiteralErr("/"))
3573
compileError("""root / "/ " """).check("", nonCanonicalLiteral("/ ", " "))
3674
compileError("""root / " /" """).check("", nonCanonicalLiteral(" /", " "))

os/test/src/ZipOpTests.scala

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@ import java.util.zip.{ZipEntry, ZipOutputStream}
1010
object ZipOpTests extends TestSuite {
1111

1212
def tests = Tests {
13-
test("level") - prep { wd =>
14-
val zipsForLevel = for (i <- Range.inclusive(0, 9)) yield {
15-
os.write.over(wd / "File.txt", Range(0, 1000).map(x => x.toString * x))
16-
os.zip(
17-
dest = wd / s"archive-$i.zip",
18-
sources = Seq(
19-
wd / "File.txt",
20-
wd / "folder1"
21-
),
22-
compressionLevel = i
23-
)
24-
}
25-
26-
// We can't compare every level because compression isn't fully monotonic,
27-
// but we compare some arbitrary levels just to sanity check things
28-
29-
// Uncompressed zip is definitely bigger than first level of compression
30-
assert(os.size(zipsForLevel(0)) > os.size(zipsForLevel(1)))
31-
// First level of compression is bigger than middle compression
32-
assert(os.size(zipsForLevel(1)) > os.size(zipsForLevel(5)))
33-
// Middle compression is bigger than best compression
34-
assert(os.size(zipsForLevel(5)) > os.size(zipsForLevel(9)))
35-
}
13+
// This test seems really flaky for some reason
14+
// test("level") - prep { wd =>
15+
// val zipsForLevel = for (i <- Range.inclusive(0, 9)) yield {
16+
// os.write.over(wd / "File.txt", Range(0, 1000).map(x => x.toString * x))
17+
// os.zip(
18+
// dest = wd / s"archive-$i.zip",
19+
// sources = Seq(
20+
// wd / "File.txt",
21+
// wd / "folder1"
22+
// ),
23+
// compressionLevel = i
24+
// )
25+
// }
26+
27+
// // We can't compare every level because compression isn't fully monotonic,
28+
// // but we compare some arbitrary levels just to sanity check things
29+
30+
// // Uncompressed zip is definitely bigger than first level of compression
31+
// assert(os.size(zipsForLevel(0)) > os.size(zipsForLevel(1)))
32+
// // First level of compression is bigger than middle compression
33+
// assert(os.size(zipsForLevel(1)) > os.size(zipsForLevel(5)))
34+
// // Middle compression is bigger than best compression
35+
// assert(os.size(zipsForLevel(5)) > os.size(zipsForLevel(9)))
36+
// }
3637
test("renaming") - prep { wd =>
3738
val zipFileName = "zip-file-test.zip"
3839
val zipFile1: os.Path = os.zip(

0 commit comments

Comments
 (0)