From ffd9a321bcb08acd65558f98ef734da8083a17eb Mon Sep 17 00:00:00 2001 From: rintcius Date: Wed, 18 Aug 2021 18:01:39 +0200 Subject: [PATCH 1/2] Replace slashes in a name with `$slash` instead of `-` --- src/Pathy/Printer.purs | 10 +++++----- test/Main.purs | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Pathy/Printer.purs b/src/Pathy/Printer.purs index 87da562..64b4af9 100644 --- a/src/Pathy/Printer.purs +++ b/src/Pathy/Printer.purs @@ -160,12 +160,12 @@ instance semigroupEscaper :: Semigroup Escaper where instance monoidEscaper :: Monoid Escaper where mempty = Escaper identity --- | An escaper that replaces all `'/'` characters in a name with `'-'`s. +-- | An escaper that replaces all `'/'` characters in a name with `$slash`. slashEscaper :: Escaper -slashEscaper = Escaper (NES.replaceAll slash dash) +slashEscaper = Escaper (NES.replaceAll slash escaped) where slash = Str.Pattern "/" - dash = NES.NonEmptyReplacement (NES.singleton '-') + escaped = NES.NonEmptyReplacement $ unsafePartial NES.unsafeFromString "$slash" -- | An escaper that replaces names `"."` and `".."` with `"$dot"` and -- | `"$dot$dot"`. @@ -175,8 +175,8 @@ dotEscaper = Escaper \s -> case NES.toString s of "." -> unsafePartial NES.unsafeFromString "$dot" _ -> s --- | An escaper that removes all slashes, converts ".." into "$dot$dot", and --- | converts "." into "$dot". +-- | An escaper that converts slashes into "$slash", ".." into "$dot$dot", and +-- | "." into "$dot". posixEscaper :: Escaper posixEscaper = slashEscaper <> dotEscaper diff --git a/test/Main.purs b/test/Main.purs index e907cff..ae7bf04 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -194,6 +194,30 @@ main = do (printPath posixPrinter $ sandboxAny rootDir) """/""" + test """printPath posixPrinter - escape . - /C/$dot/""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy ".")) + """/C/$dot/""" + + test """printPath posixPrinter - escape .. - /C/$dot$dot/""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy "..")) + """/C/$dot$dot/""" + + test """printPath posixPrinter - don't escape ... - /C/.../""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy "...")) + """/C/.../""" + + test """printPath posixPrinter - don't escape foo.bar - /C/foo.bar/""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy "foo.bar")) + """/C/foo.bar/""" + + test """printPath posixPrinter - escape / - /C/$slash/""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy "/")) + """/C/$slash/""" + + test """printPath posixPrinter - escape foo/bar - /C/foo$slashbar/""" + (printPath posixPrinter $ sandboxAny $ rootDir dir (Proxy :: Proxy "C") dir (Proxy :: Proxy "foo/bar")) + """/C/foo$slashbar/""" + test' "() - ./../foo/" (parentOf currentDir dirFoo) "./../foo/" From 8005864bdd31ba64d8aa260b8ad48fd1eadeb331 Mon Sep 17 00:00:00 2001 From: rintcius Date: Wed, 18 Aug 2021 18:22:19 +0200 Subject: [PATCH 2/2] Update changelog for #48 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd45994..33d9fe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: +- Changed `slashEscaper`: replace slashes in a name with `$slash` instead of `-` (#48 by @rintcius) ## [v8.1.0](https://github.com/purescript-contrib/purescript-pathy/releases/tag/v8.1.0) - 2021-05-06