net.urllib: allow urllib.parse_query("format=%l")

This commit is contained in:
Delyan Angelov 2021-03-30 20:14:10 +03:00
parent 683eaad66f
commit dcab79146b
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 27 additions and 14 deletions

View file

@ -53,8 +53,9 @@ fn should_escape(c byte, mode EncodingMode) bool {
// we could possibly allow, and parse will reject them if we
// escape them (because hosts can`t use %-encoding for
// ASCII bytes).
if
c in [`!`, `$`, `&`, `\\`, `(`, `)`, `*`, `+`, `,`, `;`, `=`, `:`, `[`, `]`, `<`, `>`, `"`] {
if c in [`!`, `$`, `&`, `\\`, `(`, `)`, `*`, `+`, `,`, `;`, `=`, `:`, `[`, `]`, `<`, `>`,
`"`,
] {
return false
}
}
@ -158,6 +159,11 @@ fn unescape(s_ string, mode EncodingMode) ?string {
}
n++
if i + 2 >= s.len || !ishex(s[i + 1]) || !ishex(s[i + 2]) {
if mode == .encode_query_component && i + 1 < s.len {
s = s[..i] + '%25' + s[(i + 1)..]
i += 4 // skip the %25 and the next character
continue
}
s = s[i..]
if s.len > 3 {
s = s[..3]
@ -789,7 +795,7 @@ pub fn parse_query(query string) ?Values {
// but any errors will be silent
fn parse_query_silent(query string) Values {
mut m := new_values()
parse_query_values(mut m, query) or { }
parse_query_values(mut m, query) or {}
return m
}