Skip to content

Commit

Permalink
fix issue nim-lang#8251 ospaths.isAbsolute: out of bound errors
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jul 12, 2018
1 parent 32441d0 commit 4f03613
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/pure/ospaths.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 "".isAbsolute.not
doAssert nil.isAbsolute.not
doAssert ".".isAbsolute.not
when defined(posix):
doAssert "/".isAbsolute
doAssert "a/".isAbsolute.not

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] != ':'
result = path[0] != ':'
elif defined(RISCOS):
result = path[0] == '$'
elif defined(posix):
Expand Down

0 comments on commit 4f03613

Please sign in to comment.