summary refs log tree commit diff stats
path: root/lib/pure/os.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-12-14 08:57:55 +0100
committerAraq <rumpf_a@web.de>2018-12-14 08:57:55 +0100
commitce9815bcf5a0ae5549be116604c2ad8ddacb17af (patch)
treebaae4e3ada293bcceb03debac605b6d79a59815d /lib/pure/os.nim
parent5b39c7aca91c1d20eb81425cf8f3854876aed475 (diff)
downloadNim-ce9815bcf5a0ae5549be116604c2ad8ddacb17af.tar.gz
os.nim: use the new pathnorm.normalizePath implementation
Diffstat (limited to 'lib/pure/os.nim')
-rw-r--r--lib/pure/os.nim49
1 files changed, 25 insertions, 24 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 6521d827c..1ad276b0a 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -984,36 +984,37 @@ proc normalizePath*(path: var string) {.rtl, extern: "nos$1", tags: [], noNimScr
   ##
   ## Warning: URL-encoded and Unicode attempts at directory traversal are not detected.
   ## Triple dot is not handled.
-  let isAbs = isAbsolute(path)
-  var stack: seq[string] = @[]
-  for p in split(path, {DirSep}):
-    case p
-    of "", ".":
-      continue
-    of "..":
-      if stack.len == 0:
-        if isAbs:
-          discard  # collapse all double dots on absoluta paths
-        else:
+  path = pathnorm.normalizePath(path)
+  when false:
+    let isAbs = isAbsolute(path)
+    var stack: seq[string] = @[]
+    for p in split(path, {DirSep}):
+      case p
+      of "", ".":
+        continue
+      of "..":
+        if stack.len == 0:
+          if isAbs:
+            discard  # collapse all double dots on absoluta paths
+          else:
+            stack.add(p)
+        elif stack[^1] == "..":
           stack.add(p)
-      elif stack[^1] == "..":
-        stack.add(p)
+        else:
+          discard stack.pop()
       else:
-        discard stack.pop()
-    else:
-      stack.add(p)
+        stack.add(p)
 
-  if isAbs:
-    path = DirSep & join(stack, $DirSep)
-  elif stack.len > 0:
-    path = join(stack, $DirSep)
-  else:
-    path = "."
+    if isAbs:
+      path = DirSep & join(stack, $DirSep)
+    elif stack.len > 0:
+      path = join(stack, $DirSep)
+    else:
+      path = "."
 
 proc normalizedPath*(path: string): string {.rtl, extern: "nos$1", tags: [], noNimScript.} =
   ## Returns a normalized path for the current OS. See `<#normalizePath>`_
-  result = path
-  normalizePath(result)
+  result = pathnorm.normalizePath(path)
 
 when defined(Windows) and not defined(nimscript):
   proc openHandle(path: string, followSymlink=true, writeAccess=false): Handle =