Skip to content
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

Allow implicit conversions from String => os.*Path to allow multiple segments if the string is a literal (500USD Bounty) #294

Closed
lihaoyi opened this issue Aug 22, 2024 · 3 comments
Labels
Milestone

Comments

@lihaoyi
Copy link
Member

lihaoyi commented Aug 22, 2024


From the maintainer Li Haoyi: I'm putting a 500USD bounty on this issue, payable by bank transfer on a merged PR implementing this.


Currently, os.pwd / "foo/bar/baz" fails. We do this to guard against people accidentally doing os.pwd / myStringValue and accidentally getting path traversal problems and such, and for people to explicitly say os.pwd / os.SubPath(myStringValue) or os.pwd / os.RelPath(myStringValue).

But if the RHS of the / is a literal string, there is no risk, and we should allow people to say os.pwd / "foo/bar/baz" instead of the more verbose os.pwd / "foo" / "bar" / "baz". This can be done by making the implicit conversion from String to SubPath/RelPath a macro that checks whether the RHS is a literal, and if so goes through a different code path that allows it to contain multiple segments automatically

@lihaoyi lihaoyi changed the title Allow implicit conversions from String => os.*Path to allow multiple segments if the string is a literal Allow implicit conversions from String => os.*Path to allow multiple segments if the string is a literal (500USD Bounty) Sep 3, 2024
@pawelsadlo
Copy link
Contributor

I will take a look

@pawelsadlo
Copy link
Contributor

@lihaoyi I think it might be possible to do by utilizing scala.ValueOf, and Singleton upper bound, do you require it to be implemented with macro?

@lihaoyi
Copy link
Member Author

lihaoyi commented Sep 3, 2024

@pawelsadlo I'd be ok with non-macro implementations. The main requirement is that it only work for literal strings and that it give some kind of useful error message when used on non-literal strings

@lefou lefou added the bounty label Sep 6, 2024
@lihaoyi lihaoyi closed this as completed Sep 10, 2024
@lefou lefou added this to the 0.10.7 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants