-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Make .ext on empty paths return "" rather than crashing with a NPE #87
Conversation
CI failure seems like a flake |
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.
Nice fix. I think I spotted one issue.
I also like the new lastOption
idea, which is effectively a lastOpt
. Definitely better than returning an empty string from .last
.
os/src/Path.scala
Outdated
@@ -193,7 +198,9 @@ trait BasePathImpl extends BasePath{ | |||
else last.slice(0, li) | |||
} | |||
|
|||
def last: String | |||
def last: String = lastOpt.getOrElse("empty path has no last segment") |
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.
Did you mean to throw an exception here?
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.
Hah good catch. I'll add a test to cover this error behavior as well
@lefou this should be ready for another look |
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.
LGTM!
This should be released as next minor release, because of the newly introduced method in the API. |
Fixes com-lihaoyi/Ammonite#1017
This is more consistent with calling
.ext
on non-empty paths which have no extension, since those currently return""
We also introduce a new a
lastOption
method, as a way to get the last segment in a list without throwing. Not sure if that's the right thing to do, or whether we should make.last
return""
(which is otherwise not a valid return value, since path segments cannot be empty).Covered with simple unit tests