summary refs log tree commit diff stats
path: root/lib/pure/pathnorm.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/pathnorm.nim
parent5b39c7aca91c1d20eb81425cf8f3854876aed475 (diff)
downloadNim-ce9815bcf5a0ae5549be116604c2ad8ddacb17af.tar.gz
os.nim: use the new pathnorm.normalizePath implementation
Diffstat (limited to 'lib/pure/pathnorm.nim')
-rw-r--r--lib/pure/pathnorm.nim21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/pure/pathnorm.nim b/lib/pure/pathnorm.nim
index a33afefbd..4a7d74bf8 100644
--- a/lib/pure/pathnorm.nim
+++ b/lib/pure/pathnorm.nim
@@ -66,19 +66,26 @@ proc addNormalizePath*(x: string; result: var string; state: var int; dirSep = D
     if (state shr 1 == 0) and isSlash(x, b):
       result.add dirSep
       state = state or 1
-    elif result.len > (state and 1) and isDotDot(x, b):
-      var d = result.len
-      # f/..
-      while (d-1) > (state and 1) and result[d-1] notin {DirSep, AltSep}:
-        dec d
-      if d > 0: setLen(result, d-1)
+    elif isDotDot(x, b):
+      if (state shr 1) >= 1:
+        var d = result.len
+        # f/..
+        while (d-1) > (state and 1) and result[d-1] notin {DirSep, AltSep}:
+          dec d
+        if d > 0:
+          setLen(result, d-1)
+          dec state, 2
+      else:
+        if result.len > 0 and result[^1] notin {DirSep, AltSep}:
+          result.add dirSep
+        result.add substr(x, b[0], b[1])
     elif isDot(x, b):
       discard "discard the dot"
     elif b[1] >= b[0]:
       if result.len > 0 and result[^1] notin {DirSep, AltSep}:
         result.add dirSep
       result.add substr(x, b[0], b[1])
-    inc state, 2
+      inc state, 2
 
 proc normalizePath*(path: string; dirSep = DirSep): string =
   ## Example: