Skip to content

Commit 2de57d4

Browse files
cryptoquicklucacasonato
authored andcommitted
Add additional percent-encode sets per the WHATWG specs.
1 parent 93b8e2f commit 2de57d4

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

percent_encoding/src/lib.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,125 @@ pub const CONTROLS: &AsciiSet = &AsciiSet {
116116
],
117117
};
118118

119+
/// The fragment percent-encode set.
120+
///
121+
/// The C0 control percent-encode set and U+0020 SPACE, U+0022 ("), U+003C (<), U+003E (>), and U+0060 (`).
122+
///
123+
/// <https://url.spec.whatwg.org/#fragment-percent-encode-set>
124+
pub const FRAGMENT: &AsciiSet = &CONTROLS
125+
// U+0020 SPACE
126+
.add(b' ')
127+
// U+0022 (")
128+
.add(b'"')
129+
// U+003C (<)
130+
.add(b'<')
131+
// U+003E (>)
132+
.add(b'>')
133+
// U+0060 (`)
134+
.add(b'`');
135+
136+
/// The query percent-encode set.
137+
///
138+
/// The C0 control percent-encode set and U+0020 SPACE, U+0022 ("), U+0023 (#), U+003C (<), and U+003E (>).
139+
///
140+
/// <https://url.spec.whatwg.org/#query-percent-encode-set>
141+
pub const QUERY: &AsciiSet = &CONTROLS
142+
// U+0020 SPACE
143+
.add(b' ')
144+
// U+0022 (")
145+
.add(b'"')
146+
// U+0023 (#)
147+
.add(b'#')
148+
// U+003C (<)
149+
.add(b'<')
150+
// U+003E (>)
151+
.add(b'>');
152+
153+
/// The special-query percent-encode set.
154+
///
155+
/// The query percent-encode set and U+0027 (').
156+
///
157+
/// <https://url.spec.whatwg.org/#special-query-percent-encode-set>
158+
pub const SPECIAL_QUERY: &AsciiSet = &QUERY
159+
// U+0027 (')
160+
.add(b'\'');
161+
162+
/// The path percent-encode set.
163+
///
164+
/// The query percent-encode set and U+003F (?), U+0060 (`), U+007B ({), and U+007D (}).
165+
///
166+
/// <https://url.spec.whatwg.org/#path-percent-encode-set>
167+
pub const PATH: &AsciiSet = &QUERY
168+
// U+003F (?)
169+
.add(b'?')
170+
// U+0060 (`)
171+
.add(b'`')
172+
// U+007B ({)
173+
.add(b'{')
174+
// U+007D (})
175+
.add(b'}');
176+
177+
/// The userinfo percent-encode set.
178+
///
179+
/// The path percent-encode set and U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([) to U+005E (^), inclusive, and U+007C (|).
180+
///
181+
/// <https://url.spec.whatwg.org/#userinfo-percent-encode-set>
182+
pub const USERINFO: &AsciiSet = &PATH
183+
// U+002F (/)
184+
.add(b'/')
185+
// U+003A (:)
186+
.add(b':')
187+
// U+003B (;)
188+
.add(b';')
189+
// U+003D (=)
190+
.add(b'=')
191+
// U+0040 (@)
192+
.add(b'@')
193+
// U+005B ([)
194+
.add(b'[')
195+
// U+005C (\)
196+
.add(b'\\')
197+
// U+005D (])
198+
.add(b']')
199+
// U+005E (^)
200+
.add(b'^')
201+
// U+007C (|)
202+
.add(b'|');
203+
204+
/// The component percent-encode set.
205+
///
206+
/// The userinfo percent-encode set and U+0024 ($) to U+0026 (&), inclusive, U+002B (+), and U+002C (,).
207+
///
208+
/// <https://url.spec.whatwg.org/#component-percent-encode-set>
209+
pub const COMPONENT: &AsciiSet = &USERINFO
210+
// U+0024 ($)
211+
.add(b'$')
212+
// U+0025 (%)
213+
.add(b'%')
214+
// U+0026 (&)
215+
.add(b'&')
216+
// U+002B (+)
217+
.add(b'+')
218+
// U+002C (,)
219+
.add(b',');
220+
221+
/// The `application/x-www-form-urlencoded` percent-encode set.
222+
///
223+
/// The component percent-encode set and U+0021 (!), U+0027 (') to U+0029 RIGHT PARENTHESIS, inclusive, and U+007E (~).
224+
///
225+
/// <https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set>
226+
pub const FORM: &AsciiSet = &COMPONENT
227+
// U+0021 (!)
228+
.add(b'!')
229+
// U+0027 (')
230+
.add(b'\'')
231+
// U+0028 LEFT PARENTHESIS
232+
.add(b'(')
233+
// U+0029 RIGHT PARENTHESIS
234+
.add(b')')
235+
// and U+007E (~)
236+
.add(b'~');
237+
119238
macro_rules! static_assert {
120239
($( $bool: expr, )+) => {
121240
fn _static_assert() {

0 commit comments

Comments
 (0)