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

feat(percent-encoding): add RFC2396 ascii sets #971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ForsakenHarmony
Copy link

@ForsakenHarmony ForsakenHarmony commented Sep 19, 2024

I know the doc comment says that you intentionally don't have a lot of sets, but I feel like common ones should probably be supported if anyone using the library has to add them.

I guess if this is unwanted, I could make a companion library, but I'm not sure if I would maintain it in case there are ever breaking changes (and I would want the add_range anyway).

Copy link
Contributor

@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest putting the add_range method and the transitions of the existing code to use it into its own PR, which can likely be merged fairly non-controversially as a good simplification.

I think it would be worth it to pull these out into a specific module (or possibly a crate) named after the RFC. There's another PR that's open to add the whatwg url definitions which are subtly different from the RFC definitions. #837. It would be good to have both these available for different circumstances. The RFC defined values are good for things defined by RFCs (backend / services etc.), while the whatwg versions are better for things more frontend / http focused.

BTW 2396 is updated by https://www.rfc-editor.org/rfc/rfc3986. The reason I came to look at this crate in the first place is that I wanted a spec compliant way to write a percent encoded query string for implementing another RFC which doesn't currently have a crate.

@@ -101,14 +101,26 @@ impl AsciiSet {
AsciiSet { mask }
}

pub const fn add_range(&self, start: u8, end: u8) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this took Range instead of two vars, then it would be more obvious that this was the half-open range (it's actually the inclusive range, but that's not obvious from the method name at all)

.add(b':')
pub const NON_ALPHANUMERIC: &AsciiSet = &ALPHA_NUM.complement();

/// [RFC2396](https://datatracker.ietf.org/doc/html/rfc2396).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking nit:

Suggested change
/// [RFC2396](https://datatracker.ietf.org/doc/html/rfc2396).
/// Lower case alpha numeric characters defined in [RFC2396](https://datatracker.ietf.org/doc/html/rfc2396#section-1.6).

A good description like this helps users searching for things (e.g. with a search engine), and the direct link to the section that these are defined in the RFC is useful when you need to dig into various things (obviously it's less useful for this particular case, but it's generally useful to have this as a general thing I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants