From b7201c81a41ab1b8c7d7d54ec371b7ee28225471 Mon Sep 17 00:00:00 2001 From: Samantha Marshall Date: Sat, 22 Apr 2017 13:33:49 -0400 Subject: [PATCH 1/2] Modifying how package install path is validated Fix: * This addresses a bug where nimble will throw an exception in the middle of installation due to trying to evaluate paths that are not normalized. This was fixed by adding some additional validation checks that involve comparing paths by normalizing them first. [#338] --- src/nimblepkg/tools.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nimblepkg/tools.nim b/src/nimblepkg/tools.nim index 29fbf5d..ebc268d 100644 --- a/src/nimblepkg/tools.nim +++ b/src/nimblepkg/tools.nim @@ -79,7 +79,14 @@ proc changeRoot*(origRoot, newRoot, path: string): string = ## newRoot: /home/test/ ## path: /home/dom/bar/blah/2/foo.txt ## Return value -> /home/test/bar/blah/2/foo.txt - if path.startsWith(origRoot): + + ## The additional check of `path.samePaths(origRoot)` is necessary to prevent + ## a regression, where by ending the `srcDir` defintion in a nimble file in a + ## trailing separator would cause the `path.startsWith(origRoot)` evaluation to + ## fail because of the value of `origRoot` would be longer than `path` due to + ## the trailing separator. This would cause this method to throw during package + ## installation. + if path.startsWith(origRoot) or path.samePaths(origRoot): return newRoot / path[origRoot.len .. path.len-1] else: raise newException(ValueError, From 05f0de449211217da01a83775b1346cd807f5f31 Mon Sep 17 00:00:00 2001 From: Samantha Marshall Date: Mon, 24 Apr 2017 13:45:31 -0400 Subject: [PATCH 2/2] Adding tests to fix for #338 Test: * Added new test case for issue #338, where package installation would fail when the `srcDir` path ended in a directory separator. --- tests/issue338/issue338.nimble | 7 +++++++ tests/issue338/src/issue338.nim | 0 tests/tester.nim | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 tests/issue338/issue338.nimble create mode 100644 tests/issue338/src/issue338.nim diff --git a/tests/issue338/issue338.nimble b/tests/issue338/issue338.nimble new file mode 100644 index 0000000..fae4ae5 --- /dev/null +++ b/tests/issue338/issue338.nimble @@ -0,0 +1,7 @@ +# Package +version = "0.1.0" +author = "Samantha Marshall" +description = "test case to validate successful install when `srcDir` value ends in a directory separator" +license = "MIT" + +srcDir = "src/" diff --git a/tests/issue338/src/issue338.nim b/tests/issue338/src/issue338.nim new file mode 100644 index 0000000..e69de29 diff --git a/tests/tester.nim b/tests/tester.nim index 6749927..8cbf3d6 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -286,6 +286,10 @@ test "issue #206": (output, exitCode) = execNimble("install", "-y") check exitCode == QuitSuccess +test "issue #338": + cd "issue338": + check execNimble("install", "-y").exitCode == QuitSuccess + test "can list": check execNimble("list").exitCode == QuitSuccess