diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2018-07-13 00:54:48 -0700 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2018-07-13 03:54:48 -0400 |
commit | 40f44a0c16a8aed8f97416f672d73f8bda6344ab (patch) | |
tree | 9d677be4f032cb93e60e8027990123ea6ed10208 /lib/pure | |
parent | 3163a0f46649bcb54e181b055bb32cc7bfec98df (diff) | |
download | Nim-40f44a0c16a8aed8f97416f672d73f8bda6344ab.tar.gz |
fix issue #8251 ospaths.isAbsolute: out of bound errors (#8291)
* fix issue #8251 ospaths.isAbsolute: out of bound errors * address comments * add reference to a spec for quirky macos paths
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/ospaths.nim | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index 305052e41..4ae5afd6c 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -423,12 +423,22 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} = ## Checks whether a given `path` is absolute. ## ## On Windows, network paths are considered absolute too. + runnableExamples: + doAssert(not "".isAbsolute) + doAssert(not ".".isAbsolute) + when defined(posix): + doAssert "/".isAbsolute + doAssert(not "a/".isAbsolute) + + if len(path) == 0: return false + when doslikeFileSystem: var len = len(path) - result = (len > 0 and path[0] in {'/', '\\'}) or + result = (path[0] in {'/', '\\'}) or (len > 1 and path[0] in {'a'..'z', 'A'..'Z'} and path[1] == ':') elif defined(macos): - result = path.len > 0 and path[0] != ':' + # according to https://perldoc.perl.org/File/Spec/Mac.html `:a` is a relative path + result = path[0] != ':' elif defined(RISCOS): result = path[0] == '$' elif defined(posix): |