From 8a7058200bdfc667b3d077b7bc8a4c0c37185759 Mon Sep 17 00:00:00 2001 From: Gabriel Gonzalez Date: Fri, 16 Jun 2017 17:30:32 -0700 Subject: [PATCH] Fix import bug when canonicalizing paths with home directories (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, if you saved the following files: ```bash $ echo "~/bar" > /tmp/foo $ echo "./baz" > ~/bar $ echo "1" > ~/baz ``` ... then you would get the following error: ```bash $ dhall <<< '/tmp/foo' ↳ ./foo ↳ ~/.bar ↳ ./baz Error: Missing file ``` This is because path canonicalization had a bug where relative directories like `./baz` do not get correctly resolved relative to home-anchored directories like `~/.bar`. The compiler instead mistakenly tried to locate a non-home-anchored `./baz` file, which does not exist. After this fix, the above code resolves correctly tries to resolve `~/baz` as the last file in the import chain and succeeds with: ```bash $ dhall <<< '/tmp/foo' Integer 1 ``` --- src/Dhall/Import.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dhall/Import.hs b/src/Dhall/Import.hs index c7a580b..8a371ba 100644 --- a/src/Dhall/Import.hs +++ b/src/Dhall/Import.hs @@ -390,7 +390,7 @@ canonicalize (File hasHome0 file0:paths0) = go currPath (File hasHome file:paths) = if Filesystem.relative file && hasHome == Homeless then go file' paths - else File hasHome0 (clean file') + else File hasHome (clean file') where file' = Filesystem.parent (removeAtFromFile file) currPath canonicalize (URL path:_) = URL path