summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-12-21 12:28:05 +0100
committerAraq <rumpf_a@web.de>2017-12-21 12:34:38 +0100
commit0181253eea4ed5a47c37140c0533bc62d7f09e68 (patch)
treed005aee100bf1afb3235d8a2afda177e8d87326e /compiler
parent3495c0a46ddb8c2763df7a2e57d91be4a7717eb8 (diff)
downloadNim-0181253eea4ed5a47c37140c0533bc62d7f09e68.tar.gz
fixes #6949
Diffstat (limited to 'compiler')
-rw-r--r--compiler/nimblecmd.nim24
1 files changed, 18 insertions, 6 deletions
diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim
index 39c3a17e7..0f9e03352 100644
--- a/compiler/nimblecmd.nim
+++ b/compiler/nimblecmd.nim
@@ -28,6 +28,10 @@ proc newVersion*(ver: string): Version =
 proc isSpecial(ver: Version): bool =
   return ($ver).len > 0 and ($ver)[0] == '#'
 
+proc isValidVersion(v: string): bool =
+  if v.len > 0:
+    if v[0] in {'#'} + Digits: return true
+
 proc `<`*(ver: Version, ver2: Version): bool =
   ## This is synced from Nimble's version module.
 
@@ -72,15 +76,23 @@ proc getPathVersion*(p: string): tuple[name, version: string] =
     result.name = p
     return
 
+  for i in sepIdx..<p.len:
+    if p[i] in {DirSep, AltSep}:
+      result.name = p
+      return
+
   result.name = p[0 .. sepIdx - 1]
   result.version = p.substr(sepIdx + 1)
 
-proc addPackage(packages: StringTableRef, p: string) =
+proc addPackage(packages: StringTableRef, p: string; info: TLineInfo) =
   let (name, ver) = getPathVersion(p)
-  let version = newVersion(ver)
-  if packages.getOrDefault(name).newVersion < version or
-     (not packages.hasKey(name)):
-    packages[name] = $version
+  if isValidVersion(ver):
+    let version = newVersion(ver)
+    if packages.getOrDefault(name).newVersion < version or
+      (not packages.hasKey(name)):
+      packages[name] = $version
+  else:
+    localError(info, "invalid package name: " & p)
 
 iterator chosen(packages: StringTableRef): string =
   for key, val in pairs(packages):
@@ -109,7 +121,7 @@ proc addPathRec(dir: string, info: TLineInfo) =
   if dir[pos] in {DirSep, AltSep}: inc(pos)
   for k,p in os.walkDir(dir):
     if k == pcDir and p[pos] != '.':
-      addPackage(packages, p)
+      addPackage(packages, p, info)
   for p in packages.chosen:
     addNimblePath(p, info)