From 96ddb12da8a38c1882566007bdae1968102a291d Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 24 Dec 2015 10:26:07 +0000 Subject: [PATCH] Fixes #126. --- src/nimblepkg/packageinfo.nim | 9 ++++++++- tests/issue126/a/issue-126.nimble | 11 +++++++++++ tests/issue126/b/issue126.nimble | 12 ++++++++++++ tests/tester.nim | 13 +++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/issue126/a/issue-126.nimble create mode 100644 tests/issue126/b/issue126.nimble diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index bc158aa..5eff70d 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -54,7 +54,7 @@ proc validatePackageName*(name: string) = if name[0] in {'0'..'9'}: raise newException(NimbleError, - "Invalid package name: cannot beging with " & name[0]) + "Invalid package name: cannot begin with " & name[0]) var prevWasUnderscore = false for c in name: @@ -90,6 +90,11 @@ proc validatePackageInfo(pkgInfo: PackageInfo, path: string) = if pkgInfo.name == "": raise newException(NimbleError, "Incorrect .nimble file: " & path & " does not contain a name field.") + + if pkgInfo.name.normalize != path.splitFile.name.normalize: + raise newException(NimbleError, + "The .nimble file name must match name specified inside it.") + if pkgInfo.version == "": raise newException(NimbleError, "Incorrect .nimble file: " & path & " does not contain a version field.") @@ -231,6 +236,8 @@ proc readPackageInfo*(nf: NimbleFile; onlyMinimalInfo=false): PackageInfo = ## populated. The isNimScript field can also be relied on. result = initPackageInfo(nf) + validatePackageName(nf.splitFile.name) + var success = false var iniError: ref NimbleError # Attempt ini-format first. diff --git a/tests/issue126/a/issue-126.nimble b/tests/issue126/a/issue-126.nimble new file mode 100644 index 0000000..1b27a24 --- /dev/null +++ b/tests/issue126/a/issue-126.nimble @@ -0,0 +1,11 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Test to see if certain characters are disallowed in pkg names." +license = "BSD" + +# Dependencies + +requires "nim >= 0.12.1" + diff --git a/tests/issue126/b/issue126.nimble b/tests/issue126/b/issue126.nimble new file mode 100644 index 0000000..255bac2 --- /dev/null +++ b/tests/issue126/b/issue126.nimble @@ -0,0 +1,12 @@ +# Package + +packageName = "foobar" +version = "0.1.0" +author = "Dominik Picheta" +description = "Test to see if certain characters are disallowed in pkg names." +license = "BSD" + +# Dependencies + +requires "nim >= 0.12.1" + diff --git a/tests/tester.nim b/tests/tester.nim index d9deea6..83b3833 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -65,6 +65,19 @@ test "issue #27": cd "issue27": check execCmdEx("../" & path & " install -y").exitCode == QuitSuccess +test "issue #126": + cd "issue126/a": + let (output, exitCode) = execCmdEx("../../" & path & " install") + let lines = output.strip.splitLines() + check exitCode != QuitSuccess + check "Invalid package name: cannot contain '-'" in lines[^1] + + cd "issue126/b": + let (output1, exitCode1) = execCmdEx("../../" & path & " install") + let lines1 = output1.strip.splitLines() + check exitCode1 != QuitSuccess + check "The .nimble file name must match name specified inside it." in lines1[^1] + test "can list": check execCmdEx(path & " list").exitCode == QuitSuccess