-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue #8251 ospaths.isAbsolute: out of bound errors #8291
Conversation
lib/pure/ospaths.nim
Outdated
(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] != ':' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be path.len == 0 or path[0] != ':'
, maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- actually
or
is not the right thing since empty path should not be absolute - however I'm already checking for
len=0
at function top-level just found another preexisting bug which my latest commit fixes: the condition here should be negated! ":" would be absolute on macos (given that ":" meant the new "/" separator);=> actually upon reading more I found this https://perldoc.perl.org/File/Spec/Mac.html and added that as reference for this non-intuitive behavior; on that note, see my post https://forum.nim-lang.org/t/4039 "should we keep supporting macos? (as opposed to macosx)"
lib/pure/ospaths.nim
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There soon will be no nil
for strings, don't write tests covering it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
when doslikeFileSystem: | ||
var len = len(path) | ||
result = (len > 0 and path[0] in {'/', '\\'}) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fail to see how removing bounds checking helps with anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the case len=0
is already handled at the very top-level of this function
lib/pure/ospaths.nim
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.not
is not a style we use anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was a workaround after hitting that bug: #8300 ; but I've fixed it to doAssert(not condition)
PTAL |
985f05d
to
7c273f3
Compare
No description provided.