Encode filepaths to be safe on Windows

This changes the file paths to use characters that are safe for Windows.

Channges the output of the following:
* Package cache directory
* Generated pkl-doc files
* Kotlin generated code

Unsafe characters are encoded as (<hex>).
For example, the colon character `:` is encoded as `(3a)`.

Additionally, this changes the cache directory prefix (package-1 to
package-2).

Follows the design of https://github.com/apple/pkl-evolution/pull/3
This commit is contained in:
Dan Chao
2024-04-26 07:34:31 -07:00
committed by Daniel Chao
parent 110dc89e86
commit a5c13e325a
36 changed files with 185 additions and 106 deletions

View File

@@ -431,4 +431,14 @@ class IoUtilsTest {
IoUtils.readString(URI("http://example.com").toURL())
}
}
@Test
fun `encodePath encodes characters reserved on windows`() {
assertThat(IoUtils.encodePath("foo:bar")).isEqualTo("foo(3a)bar")
assertThat(IoUtils.encodePath("<>:\"\\|?*")).isEqualTo("(3c)(3e)(3a)(22)(5c)(7c)(3f)(2a)")
assertThat(IoUtils.encodePath("foo(3a)bar")).isEqualTo("foo((3a)bar")
assertThat(IoUtils.encodePath("(")).isEqualTo("((")
assertThat(IoUtils.encodePath("3a)")).isEqualTo("3a)")
assertThat(IoUtils.encodePath("foo/bar/baz")).isEqualTo("foo/bar/baz")
}
}