-
Notifications
You must be signed in to change notification settings - Fork 346
percent-encoding: make sets be values of one type, instead of types that implement a trait #519
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
Conversation
…hat implement a trait Fix #388
bc4503b
to
7f1bd6c
Compare
@bors-servo r+ Niceè |
📌 Commit 7f1bd6c has been approved by |
percent-encoding: make sets be values of one type, instead of types that implement a trait Fix #388 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/519) <!-- Reviewable:end -->
💔 Test failed - checks-travis |
@bors-servo r=nox Raised minimum Rust version |
📌 Commit a1fe49e has been approved by |
percent-encoding: make sets be values of one type, instead of types that implement a trait Fix #388 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/519) <!-- Reviewable:end -->
☀️ Test successful - checks-travis |
Ah, you removed |
We don't have the resources to maintain such a guide. |
A quick look at the diff shows that it was just renamed to |
... besides it is moved to a different crate and no longer exposed. |
I see. One could write a patch to expose it again from the |
If you would accept such a patch, I can try to write it I guess. |
I think Simon removed it because he didn't expect it to have any users, but if there are I don't really see a reason to reject such patch. You may want to confirm that with him though. |
See discussion in #529: What is the context of the code you’re writing? If it’s URL-related, does the If you’re implementing some spec, the removal of various pre-defined sets from the precent-encoding is intended to nudge you toward reading that spec and defining your own set based on it. |
The context is that I need a url as a string, and I have a hard-coded string template for it already. It's true that The related code can be found here: https://github.com/upsuper/telegram-rustevalbot/blob/984a2a1b7c8d7631e74ef23001a717912b3f212d/src/cratesio/mod.rs#L124-L128 |
I wonder if we could provide a way to extract the The benefit of not exposing those sets directly and going through |
It's not going to hurt any performance... it's just an extra annoyance to use it for this simple case. |
For justification, compare the following code: fn generate_url(base_url: &str, name: &str) -> String {
let mut url = Url::parse(base_url).unwrap();
url.path_segments_mut().unwrap().push(name);
url.to_string()
}
let crate_url = generate_url("https://crates.io/crates", name);
let doc_url = generate_url("https://docs.rs/crate", name); vs. let name_url = utf8_percent_encode(name, PATH_SEGMENT_ENCODE_SET);
let crate_url = format!("https://crates.io/crates/{}", name_url);
let doc_url = format!("https://docs.rs/crate/{}", name_url); My intuition is that the first piece of code is more error-prone and dangerous than the second given the extra |
The other alternative is: use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
/// https://url.spec.whatwg.org/#fragment-percent-encode-set
const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
/// https://url.spec.whatwg.org/#path-percent-encode-set
const PATH: &AsciiSet = &FRAGMENT.add(b'#').add(b'?').add(b'{').add(b'}');
utf8_percent_encode(name, PATH) Additionally, per https://doc.rust-lang.org/cargo/reference/manifest.html#the-name-field crates.io only allows ASCII alphanumeric characters and |
Fix #388
This change is