-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat(stdlib): Add Uri
module
#1970
Conversation
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 looks great.
Also looks like the docs need to be regenerated.
31d0416
to
9819f1d
Compare
Alex, this looks fantastic and really useful. I also learnt a lot about what are valid URLs (I swore you could only include? once!). My only comment before I press approve is that pretty much every language calls urlEncode what you call percentageEncode, and I wondered if we should standardize on that? (although wikipedia says it's officially percent encode... https://en.wikipedia.org/wiki/Percent-encoding) |
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.
What made you return an abstract record and have access methods rather than just return the record?
@ospencer This is following the pattern I've seen used in OCaml libraries for encapsulating data/providing a uniform interface for simple & computed data. In this particular instance not much is really being encapsulated but I think having these access methods still provides a degree of uniformity. Kind of like the idea behind properties in C# or getters in Java, where the interface to a data type can remain disconnected from the implementation. I guess just providing the record directly here would be simpler though and would make the API smaller. I'm not heavily set in either direction so I'm open to arguments in either direction |
I don't mind it, I was just curious! I looked at the API first and it made me think some kind of computation was happening since I already called this |
Yeah that makes sense. I can change it to a provided record |
I'd wait to hear what the stdlib experts say :P |
@marcusroberts good point, I also just did a survey of a handful of languages and they all seem to prefer the terminology of "URL encoding". Though RFC 3986 uses the terminology of "percent encoding" so I guess it's a decision on whether we want to use the official terminology or the common lingo 🤷 |
I think I agree here. Usually if you are calling a function on some abstract type, it'd be due to delayed processing. For example, a Rust library I was using was storing the full cookie The caveat to the above is returning records with functions attached; instead, I would say should be functions that take the record (such as our Queue, Map, etc data structures). |
9819f1d
to
8462b35
Compare
I think we should use the common terminology but keep our docs searchable by including the |
8462b35
to
f10b70e
Compare
@spotandjake @marcusroberts What about just |
4cadfc8
to
8eaff8d
Compare
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.
Thanks for changing the name - it looks great to me now!
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.
Thoughts on changing all of the places we say percentEncode
/percentDecode
to just encode
/decode
?
return true | ||
} | ||
|
||
// Lowercase all non-percent-encoded alphabetical characters |
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 think we should make issues for String.lowercaseAscii
and String.uppercaseAscii
and todos that reference it 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.
What do you mean here? This function uses the char toAsciiLowercase
function
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.
Instead of exploding and iterating the Char version, it'd be handy to just call lowercase
on the string. Unless I didn't read this hard enough.
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 think you'd still need some custom logic to only lowercase the characters that aren't percent-encode triples so not sure if there'd be a super huge advantage to using lowercase on the whole string
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.
Phenomenal work on this! I learned a ton about URIs just from reading your implementation. Excited to use this soon.
Looks like this needs docs regenerated |
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.
Sorry I did those as individuals. I always thought "surely this will be the last one" until the actual last one.
URI parsing and utility module, mostly conforming to RFC 3986.