@@ -2,6 +2,7 @@ from collections import Dict
22from utils import Variant
33from lightbug_http.io.bytes import Bytes, bytes
44from lightbug_http.strings import (
5+ find_all,
56 strSlash,
67 strHttp11,
78 strHttp10,
@@ -12,16 +13,11 @@ from lightbug_http.strings import (
1213)
1314
1415
15- fn find_all (s : String, sub_str : String) -> List[Int]:
16- match_idxs = List[Int]()
17- var current_idx : Int = s.find(sub_str)
18- while current_idx > - 1 :
19- match_idxs.append(current_idx)
20- current_idx = s.find(sub_str, start = current_idx + 1 )
21- return match_idxs^
22-
23-
24- fn unquote [expand_plus : Bool = False ](input_str : String) -> String:
16+ fn unquote [
17+ expand_plus : Bool = False
18+ ](
19+ input_str : String, disallowed_escapes : List[String] = List[String]()
20+ ) -> String:
2521 var encoded_str = input_str.replace(
2622 QueryDelimiters.PLUS_ESCAPED_SPACE , " "
2723 ) if expand_plus else input_str
@@ -70,7 +66,12 @@ fn unquote[expand_plus: Bool = False](input_str: String) -> String:
7066
7167 if len (str_bytes) > 0 :
7268 str_bytes.append(0x 00 )
73- sub_strings.append(String(str_bytes))
69+ var sub_str_from_bytes = String(str_bytes)
70+ for disallowed in disallowed_escapes:
71+ sub_str_from_bytes = sub_str_from_bytes.replace(
72+ disallowed[], " "
73+ )
74+ sub_strings.append(sub_str_from_bytes)
7475 str_bytes.clear()
7576
7677 slice_start = current_offset
@@ -152,10 +153,14 @@ struct URI(Writable, Stringable, Representable):
152153 var original_path : String
153154 var query_string : String
154155 if n >= 0 :
155- original_path = unquote(request_uri[:n])
156+ original_path = unquote(
157+ request_uri[:n], disallowed_escapes = List(str (" /" ))
158+ )
156159 query_string = request_uri[n + 1 :]
157160 else :
158- original_path = unquote(request_uri)
161+ original_path = unquote(
162+ request_uri, disallowed_escapes = List(str (" /" ))
163+ )
159164 query_string = " "
160165
161166 var queries = QueryMap()
@@ -164,13 +169,12 @@ struct URI(Writable, Stringable, Representable):
164169
165170 for item in query_items:
166171 var key_val = item[].split(QueryDelimiters.ITEM_ASSIGN , 1 )
172+ var key = unquote[expand_plus=True ](key_val[0 ])
167173
168- if key_val[ 0 ] :
169- queries[key_val[ 0 ] ] = " "
174+ if key :
175+ queries[key ] = " "
170176 if len (key_val) == 2 :
171- queries[key_val[0 ]] = unquote[expand_plus=True ](
172- key_val[1 ]
173- )
177+ queries[key] = unquote[expand_plus=True ](key_val[1 ])
174178
175179 return URI(
176180 _original_path = original_path,
0 commit comments