Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Sep 10, 2024
1 parent 4262d5c commit 3bedb40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ string, int or set representations of the `os.PermSet` via:
[#main]
=== main

* Make `os.pwd` modifiable via the `os.dynamicPwd0`
* Allow multi-segment paths segments for literals https://github.com/com-lihaoyi/os-lib/pull/297

[#0-10-6]
=== 0.10.6
Expand Down
19 changes: 8 additions & 11 deletions os/src/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,31 @@ object BasePath {
def checkSegment(s: String) = {
def fail(msg: String) = throw PathError.InvalidSegment(s, msg)
def considerStr =
"use the Path(...) or RelPath(...) constructor calls to convert them. "
"If you are dealing with dynamic path-strings coming from external sources, " +
"use the Path(...)/RelPath(...)/SubPath(...) constructor calls to convert them."

s.indexOf('/') match {
case -1 => // do nothing
case c => fail(
s"[/] is not a valid character to appear in a path segment. " +
"If you want to parse an absolute or relative path that may have " +
"multiple segments, e.g. path-strings coming from external sources " +
s"[/] is not a valid character to appear in a non-literal path segment. " +
considerStr
)

}
def externalStr = "If you are dealing with path-strings coming from external sources, "
s match {
case "" =>
fail(
"OS-Lib does not allow empty path segments " +
externalStr + considerStr
"OS-Lib does not allow empty path segments. " +
considerStr
)
case "." =>
fail(
"OS-Lib does not allow [.] as a path segment " +
externalStr + considerStr
"OS-Lib does not allow [.] in a non-literal path segment. " +
considerStr
)
case ".." =>
fail(
"OS-Lib does not allow [..] as a path segment " +
externalStr +
"OS-Lib does not allow [..] in a non-literal path segment. " +
considerStr +
"If you want to use the `..` segment manually to represent going up " +
"one level in the path, use the `up` segment from `os.up` " +
Expand Down
8 changes: 7 additions & 1 deletion os/test/src/PathTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,13 @@ object PathTests extends TestSuite {

val PathError.InvalidSegment("Main/.scala", msg1) = ex

assert(msg1.contains("[/] is not a valid character to appear in a path segment"))
assert(
msg1.contains(
"[/] is not a valid character to appear in a non-literal path segment. If you are "+
"dealing with dynamic path-strings coming from external sources, use the "+
"Path(...)/RelPath(...)/SubPath(...) constructor calls to convert them."
)
)

val ex2 = intercept[PathError.InvalidSegment](root / "hello" / nonLiteral("..") / "world")

Expand Down

0 comments on commit 3bedb40

Please sign in to comment.