diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2018-12-19 04:55:51 -0800 |
---|---|---|
committer | Timothee Cour <timothee.cour2@gmail.com> | 2018-12-19 16:11:23 -0800 |
commit | 656770402c85227c0597f260f593834b1bd2d3f5 (patch) | |
tree | bb9dd7119e8c32fbd1c79f23686745e3df7d6c3b /lib/pure | |
parent | c129107b32528a39d82a0459f8c22ab68fc70a43 (diff) | |
download | Nim-656770402c85227c0597f260f593834b1bd2d3f5.tar.gz |
fix #8255 numerous issues with splitFile
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/os.nim | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 68c1e28a2..46e4e7b69 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -349,19 +349,28 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {. ## If `path` has no extension, `ext` is the empty string. ## If `path` has no directory component, `dir` is the empty string. ## If `path` has no filename component, `name` and `ext` are empty strings. - if path.len == 0 or path[path.len-1] in {DirSep, AltSep}: - result = (path, "", "") + if path.len == 0 or path[^1] in {DirSep, AltSep}: + if path.len == 1: + # issue #8255 + result = (path[0 .. ^1], "", "") + else: + result = (path[0 ..< ^1], "", "") else: var sepPos = -1 var dotPos = path.len for i in countdown(len(path)-1, 0): if path[i] == ExtSep: if dotPos == path.len and i > 0 and - path[i-1] notin {DirSep, AltSep}: dotPos = i + path[i-1] notin {DirSep, AltSep, ExtSep}: dotPos = i elif path[i] in {DirSep, AltSep}: sepPos = i break - result.dir = substr(path, 0, sepPos-1) + if sepPos-1 >= 0: + result.dir = substr(path, 0, sepPos-1) + elif path[0] in {DirSep, AltSep}: + # issue #8255 + result.dir = $path[0] + result.name = substr(path, sepPos+1, dotPos-1) result.ext = substr(path, dotPos) |