From 4f03613651b3b957254ada89de3ebe4637921bcc Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 11 Jul 2018 19:05:06 -0700 Subject: [PATCH] fix issue #8251 ospaths.isAbsolute: out of bound errors --- lib/pure/ospaths.nim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index 305052e41913a..584bfb0cc673c 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 "".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):