spikard 0.2.0 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/spikard_rb/Cargo.toml +3 -2
- data/lib/spikard/version.rb +1 -1
- data/vendor/bundle/ruby/3.3.0/gems/diff-lcs-1.6.2/mise.toml +5 -0
- data/vendor/crates/spikard-core/Cargo.toml +40 -0
- data/vendor/crates/spikard-core/src/bindings/mod.rs +3 -0
- data/vendor/crates/spikard-core/src/bindings/response.rs +133 -0
- data/vendor/crates/spikard-core/src/debug.rs +63 -0
- data/vendor/crates/spikard-core/src/di/container.rs +726 -0
- data/vendor/crates/spikard-core/src/di/dependency.rs +273 -0
- data/vendor/crates/spikard-core/src/di/error.rs +118 -0
- data/vendor/crates/spikard-core/src/di/factory.rs +538 -0
- data/vendor/crates/spikard-core/src/di/graph.rs +545 -0
- data/vendor/crates/spikard-core/src/di/mod.rs +192 -0
- data/vendor/crates/spikard-core/src/di/resolved.rs +411 -0
- data/vendor/crates/spikard-core/src/di/value.rs +283 -0
- data/vendor/crates/spikard-core/src/http.rs +153 -0
- data/vendor/crates/spikard-core/src/lib.rs +28 -0
- data/vendor/crates/spikard-core/src/lifecycle.rs +422 -0
- data/vendor/crates/spikard-core/src/parameters.rs +719 -0
- data/vendor/crates/spikard-core/src/problem.rs +310 -0
- data/vendor/crates/spikard-core/src/request_data.rs +189 -0
- data/vendor/crates/spikard-core/src/router.rs +249 -0
- data/vendor/crates/spikard-core/src/schema_registry.rs +183 -0
- data/vendor/crates/spikard-core/src/type_hints.rs +304 -0
- data/vendor/crates/spikard-core/src/validation.rs +699 -0
- data/vendor/crates/spikard-http/Cargo.toml +58 -0
- data/vendor/crates/spikard-http/src/auth.rs +247 -0
- data/vendor/crates/spikard-http/src/background.rs +249 -0
- data/vendor/crates/spikard-http/src/bindings/mod.rs +3 -0
- data/vendor/crates/spikard-http/src/bindings/response.rs +1 -0
- data/vendor/crates/spikard-http/src/body_metadata.rs +8 -0
- data/vendor/crates/spikard-http/src/cors.rs +490 -0
- data/vendor/crates/spikard-http/src/debug.rs +63 -0
- data/vendor/crates/spikard-http/src/di_handler.rs +423 -0
- data/vendor/crates/spikard-http/src/handler_response.rs +190 -0
- data/vendor/crates/spikard-http/src/handler_trait.rs +228 -0
- data/vendor/crates/spikard-http/src/handler_trait_tests.rs +284 -0
- data/vendor/crates/spikard-http/src/lib.rs +529 -0
- data/vendor/crates/spikard-http/src/lifecycle/adapter.rs +149 -0
- data/vendor/crates/spikard-http/src/lifecycle.rs +428 -0
- data/vendor/crates/spikard-http/src/middleware/mod.rs +285 -0
- data/vendor/crates/spikard-http/src/middleware/multipart.rs +86 -0
- data/vendor/crates/spikard-http/src/middleware/urlencoded.rs +147 -0
- data/vendor/crates/spikard-http/src/middleware/validation.rs +287 -0
- data/vendor/crates/spikard-http/src/openapi/mod.rs +309 -0
- data/vendor/crates/spikard-http/src/openapi/parameter_extraction.rs +190 -0
- data/vendor/crates/spikard-http/src/openapi/schema_conversion.rs +308 -0
- data/vendor/crates/spikard-http/src/openapi/spec_generation.rs +195 -0
- data/vendor/crates/spikard-http/src/parameters.rs +1 -0
- data/vendor/crates/spikard-http/src/problem.rs +1 -0
- data/vendor/crates/spikard-http/src/query_parser.rs +369 -0
- data/vendor/crates/spikard-http/src/response.rs +399 -0
- data/vendor/crates/spikard-http/src/router.rs +1 -0
- data/vendor/crates/spikard-http/src/schema_registry.rs +1 -0
- data/vendor/crates/spikard-http/src/server/handler.rs +80 -0
- data/vendor/crates/spikard-http/src/server/lifecycle_execution.rs +98 -0
- data/vendor/crates/spikard-http/src/server/mod.rs +805 -0
- data/vendor/crates/spikard-http/src/server/request_extraction.rs +119 -0
- data/vendor/crates/spikard-http/src/sse.rs +447 -0
- data/vendor/crates/spikard-http/src/testing/form.rs +14 -0
- data/vendor/crates/spikard-http/src/testing/multipart.rs +60 -0
- data/vendor/crates/spikard-http/src/testing/test_client.rs +285 -0
- data/vendor/crates/spikard-http/src/testing.rs +377 -0
- data/vendor/crates/spikard-http/src/type_hints.rs +1 -0
- data/vendor/crates/spikard-http/src/validation.rs +1 -0
- data/vendor/crates/spikard-http/src/websocket.rs +324 -0
- data/vendor/crates/spikard-rb/Cargo.toml +42 -0
- data/vendor/crates/spikard-rb/build.rs +8 -0
- data/vendor/crates/spikard-rb/src/background.rs +63 -0
- data/vendor/crates/spikard-rb/src/config.rs +294 -0
- data/vendor/crates/spikard-rb/src/conversion.rs +392 -0
- data/vendor/crates/spikard-rb/src/di.rs +409 -0
- data/vendor/crates/spikard-rb/src/handler.rs +534 -0
- data/vendor/crates/spikard-rb/src/lib.rs +2020 -0
- data/vendor/crates/spikard-rb/src/lifecycle.rs +267 -0
- data/vendor/crates/spikard-rb/src/server.rs +283 -0
- data/vendor/crates/spikard-rb/src/sse.rs +231 -0
- data/vendor/crates/spikard-rb/src/test_client.rs +404 -0
- data/vendor/crates/spikard-rb/src/test_sse.rs +143 -0
- data/vendor/crates/spikard-rb/src/test_websocket.rs +221 -0
- data/vendor/crates/spikard-rb/src/websocket.rs +233 -0
- metadata +81 -2
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
//! Fast query string parser
|
|
2
|
+
//!
|
|
3
|
+
//! Vendored and adapted from https://github.com/litestar-org/fast-query-parsers
|
|
4
|
+
//! Original author: Naaman Hirschfeld (same author as Spikard)
|
|
5
|
+
//!
|
|
6
|
+
//! This parser handles multiple values for the same key and auto-converts types.
|
|
7
|
+
|
|
8
|
+
use lazy_static::lazy_static;
|
|
9
|
+
use regex::Regex;
|
|
10
|
+
use rustc_hash::FxHashMap;
|
|
11
|
+
use serde_json::{Value, from_str};
|
|
12
|
+
use std::borrow::Cow;
|
|
13
|
+
use std::convert::Infallible;
|
|
14
|
+
|
|
15
|
+
lazy_static! {
|
|
16
|
+
static ref PARENTHESES_RE: Regex = Regex::new(r"(^\[.*\]$|^\{.*\}$)").unwrap();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// URL-decode a byte slice, replacing '+' with space and handling percent-encoding.
|
|
20
|
+
///
|
|
21
|
+
/// Optimized to avoid intermediate allocations by:
|
|
22
|
+
/// - Processing bytes directly without intermediate String conversion
|
|
23
|
+
/// - Using Cow to avoid allocation when no encoding is present
|
|
24
|
+
/// - Replacing '+' during decoding rather than as a separate pass
|
|
25
|
+
#[inline]
|
|
26
|
+
fn url_decode_optimized(input: &[u8]) -> Cow<'_, str> {
|
|
27
|
+
let has_encoded = input.iter().any(|&b| b == b'+' || b == b'%');
|
|
28
|
+
|
|
29
|
+
if !has_encoded {
|
|
30
|
+
return match std::str::from_utf8(input) {
|
|
31
|
+
Ok(s) => Cow::Borrowed(s),
|
|
32
|
+
Err(_) => Cow::Owned(String::from_utf8_lossy(input).into_owned()),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let mut result = Vec::with_capacity(input.len());
|
|
37
|
+
let mut i = 0;
|
|
38
|
+
|
|
39
|
+
while i < input.len() {
|
|
40
|
+
match input[i] {
|
|
41
|
+
b'+' => {
|
|
42
|
+
result.push(b' ');
|
|
43
|
+
i += 1;
|
|
44
|
+
}
|
|
45
|
+
b'%' if i + 2 < input.len() => {
|
|
46
|
+
if let (Some(hi), Some(lo)) = (
|
|
47
|
+
char::from(input[i + 1]).to_digit(16),
|
|
48
|
+
char::from(input[i + 2]).to_digit(16),
|
|
49
|
+
) {
|
|
50
|
+
result.push((hi * 16 + lo) as u8);
|
|
51
|
+
i += 3;
|
|
52
|
+
} else {
|
|
53
|
+
result.push(input[i]);
|
|
54
|
+
i += 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
b => {
|
|
58
|
+
result.push(b);
|
|
59
|
+
i += 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Cow::Owned(String::from_utf8_lossy(&result).into_owned())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Parse a query string into a vector of (key, value) tuples.
|
|
68
|
+
///
|
|
69
|
+
/// Handles URL encoding and supports multiple values for the same key.
|
|
70
|
+
///
|
|
71
|
+
/// # Arguments
|
|
72
|
+
/// * `qs` - The query string bytes
|
|
73
|
+
/// * `separator` - The separator character (typically '&')
|
|
74
|
+
///
|
|
75
|
+
/// # Example
|
|
76
|
+
/// ```ignore
|
|
77
|
+
/// let result = parse_query_string(b"foo=1&foo=2&bar=test", '&');
|
|
78
|
+
/// // vec![("foo", "1"), ("foo", "2"), ("bar", "test")]
|
|
79
|
+
/// ```
|
|
80
|
+
///
|
|
81
|
+
/// # Performance
|
|
82
|
+
/// Optimized to minimize allocations by:
|
|
83
|
+
/// - Processing bytes directly without intermediate String allocation
|
|
84
|
+
/// - Using custom URL decoder that handles '+' replacement in one pass
|
|
85
|
+
/// - Pre-allocating result vector
|
|
86
|
+
#[inline]
|
|
87
|
+
pub fn parse_query_string(qs: &[u8], separator: char) -> Vec<(String, String)> {
|
|
88
|
+
if qs.is_empty() {
|
|
89
|
+
return Vec::new();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let separator_byte = separator as u8;
|
|
93
|
+
let mut result = Vec::with_capacity(8);
|
|
94
|
+
|
|
95
|
+
let mut start = 0;
|
|
96
|
+
let mut i = 0;
|
|
97
|
+
|
|
98
|
+
while i <= qs.len() {
|
|
99
|
+
if i == qs.len() || qs[i] == separator_byte {
|
|
100
|
+
if i > start {
|
|
101
|
+
let pair = &qs[start..i];
|
|
102
|
+
|
|
103
|
+
if let Some(eq_pos) = pair.iter().position(|&b| b == b'=') {
|
|
104
|
+
let key = url_decode_optimized(&pair[..eq_pos]);
|
|
105
|
+
let value = url_decode_optimized(&pair[eq_pos + 1..]);
|
|
106
|
+
result.push((key.into_owned(), value.into_owned()));
|
|
107
|
+
} else {
|
|
108
|
+
let key = url_decode_optimized(pair);
|
|
109
|
+
result.push((key.into_owned(), String::new()));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
start = i + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
i += 1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
result
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Decode a string value into a JSON Value with type conversion.
|
|
123
|
+
///
|
|
124
|
+
/// Handles:
|
|
125
|
+
/// - JSON objects and arrays (if wrapped in brackets)
|
|
126
|
+
/// - Booleans (true/false/1/0, case-insensitive)
|
|
127
|
+
/// - Null
|
|
128
|
+
/// - Numbers (if parse_numbers is true)
|
|
129
|
+
/// - Strings (fallback)
|
|
130
|
+
#[inline]
|
|
131
|
+
fn decode_value(json_str: String, parse_numbers: bool) -> Value {
|
|
132
|
+
if PARENTHESES_RE.is_match(json_str.as_str()) {
|
|
133
|
+
let result: Value = match from_str(json_str.as_str()) {
|
|
134
|
+
Ok(value) => value,
|
|
135
|
+
Err(_) => match from_str(json_str.replace('\'', "\"").as_str()) {
|
|
136
|
+
Ok(normalized) => normalized,
|
|
137
|
+
Err(_) => Value::Null,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let normalized = json_str.replace('"', "");
|
|
144
|
+
|
|
145
|
+
let json_boolean = parse_boolean(&normalized);
|
|
146
|
+
let json_null = Ok::<_, Infallible>(normalized == "null");
|
|
147
|
+
|
|
148
|
+
if parse_numbers {
|
|
149
|
+
let json_integer = normalized.parse::<i64>();
|
|
150
|
+
let json_float = normalized.parse::<f64>();
|
|
151
|
+
return match (json_integer, json_float, json_boolean, json_null) {
|
|
152
|
+
(Ok(json_integer), _, _, _) => Value::from(json_integer),
|
|
153
|
+
(_, Ok(json_float), _, _) => Value::from(json_float),
|
|
154
|
+
(_, _, Ok(json_boolean), _) => Value::from(json_boolean),
|
|
155
|
+
(_, _, _, Ok(true)) => Value::Null,
|
|
156
|
+
_ => Value::from(normalized),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
match (json_boolean, json_null) {
|
|
161
|
+
(Ok(json_boolean), _) => Value::from(json_boolean),
|
|
162
|
+
(_, Ok(true)) => Value::Null,
|
|
163
|
+
_ => Value::from(normalized),
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// Parse a boolean value from a string.
|
|
168
|
+
///
|
|
169
|
+
/// Accepts:
|
|
170
|
+
/// - "true" (case-insensitive) → true
|
|
171
|
+
/// - "false" (case-insensitive) → false
|
|
172
|
+
/// - "1" → true
|
|
173
|
+
/// - "0" → false
|
|
174
|
+
/// - "" (empty string) → Err (don't coerce, preserve as empty string)
|
|
175
|
+
#[inline]
|
|
176
|
+
fn parse_boolean(s: &str) -> Result<bool, ()> {
|
|
177
|
+
let lower = s.to_lowercase();
|
|
178
|
+
if lower == "true" || s == "1" {
|
|
179
|
+
Ok(true)
|
|
180
|
+
} else if lower == "false" || s == "0" {
|
|
181
|
+
Ok(false)
|
|
182
|
+
} else {
|
|
183
|
+
Err(())
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Parse a query string into a JSON Value.
|
|
188
|
+
///
|
|
189
|
+
/// This function:
|
|
190
|
+
/// - Handles multiple values for the same key (creates arrays)
|
|
191
|
+
/// - Auto-converts types (numbers, booleans, null, objects, arrays)
|
|
192
|
+
/// - Collapses single-item arrays into single values
|
|
193
|
+
///
|
|
194
|
+
/// # Arguments
|
|
195
|
+
/// * `qs` - The query string bytes
|
|
196
|
+
/// * `parse_numbers` - Whether to parse numeric strings into numbers
|
|
197
|
+
///
|
|
198
|
+
/// # Example
|
|
199
|
+
/// ```ignore
|
|
200
|
+
/// let result = parse_query_string_to_json(b"foo=1&foo=2&bar=test&active=true", true);
|
|
201
|
+
/// // {"foo": [1, 2], "bar": "test", "active": true}
|
|
202
|
+
/// ```
|
|
203
|
+
#[inline]
|
|
204
|
+
pub fn parse_query_string_to_json(qs: &[u8], parse_numbers: bool) -> Value {
|
|
205
|
+
let mut array_map: FxHashMap<String, Vec<Value>> = FxHashMap::default();
|
|
206
|
+
|
|
207
|
+
for (key, value) in parse_query_string(qs, '&') {
|
|
208
|
+
match array_map.get_mut(&key) {
|
|
209
|
+
Some(entry) => {
|
|
210
|
+
entry.push(decode_value(value, parse_numbers));
|
|
211
|
+
}
|
|
212
|
+
None => {
|
|
213
|
+
array_map.insert(key, vec![decode_value(value, parse_numbers)]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
array_map
|
|
219
|
+
.iter()
|
|
220
|
+
.map(|(key, value)| {
|
|
221
|
+
if value.len() == 1 {
|
|
222
|
+
(key, value[0].to_owned())
|
|
223
|
+
} else {
|
|
224
|
+
(key, Value::Array(value.to_owned()))
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
.collect::<Value>()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#[cfg(test)]
|
|
231
|
+
mod tests {
|
|
232
|
+
use super::*;
|
|
233
|
+
use serde_json::{json, to_string};
|
|
234
|
+
|
|
235
|
+
fn eq_str(value: Value, string: &str) {
|
|
236
|
+
assert_eq!(&to_string(&value).unwrap_or_default(), string)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
#[test]
|
|
240
|
+
fn test_ampersand_separator() {
|
|
241
|
+
assert_eq!(
|
|
242
|
+
parse_query_string(b"key=1&key=2&anotherKey=a&yetAnother=z", '&'),
|
|
243
|
+
vec![
|
|
244
|
+
(String::from("key"), String::from("1")),
|
|
245
|
+
(String::from("key"), String::from("2")),
|
|
246
|
+
(String::from("anotherKey"), String::from("a")),
|
|
247
|
+
(String::from("yetAnother"), String::from("z")),
|
|
248
|
+
]
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[test]
|
|
253
|
+
fn test_handles_url_encoded_ampersand() {
|
|
254
|
+
assert_eq!(
|
|
255
|
+
parse_query_string(b"first=%26%40A.ac&second=aaa", '&'),
|
|
256
|
+
vec![
|
|
257
|
+
(String::from("first"), String::from("&@A.ac")),
|
|
258
|
+
(String::from("second"), String::from("aaa")),
|
|
259
|
+
]
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#[test]
|
|
264
|
+
fn parse_query_string_to_json_parses_simple_string() {
|
|
265
|
+
eq_str(parse_query_string_to_json(b"0=foo", true), r#"{"0":"foo"}"#);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
#[test]
|
|
269
|
+
fn parse_query_string_to_json_parses_numbers() {
|
|
270
|
+
assert_eq!(parse_query_string_to_json(b"a=1", true), json!({"a": 1}));
|
|
271
|
+
assert_eq!(parse_query_string_to_json(b"a=1.1", true), json!({"a": 1.1}));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
#[test]
|
|
275
|
+
fn parse_query_string_to_json_parses_booleans() {
|
|
276
|
+
assert_eq!(parse_query_string_to_json(b"a=true", false), json!({"a": true}));
|
|
277
|
+
assert_eq!(parse_query_string_to_json(b"a=false", false), json!({"a": false}));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
#[test]
|
|
281
|
+
fn parse_query_string_to_json_parses_booleans_from_numbers() {
|
|
282
|
+
assert_eq!(parse_query_string_to_json(b"a=1", false), json!({"a": true}));
|
|
283
|
+
assert_eq!(parse_query_string_to_json(b"a=0", false), json!({"a": false}));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
#[test]
|
|
287
|
+
fn parse_query_string_to_json_parses_case_insensitive_booleans() {
|
|
288
|
+
assert_eq!(parse_query_string_to_json(b"a=True", false), json!({"a": true}));
|
|
289
|
+
assert_eq!(parse_query_string_to_json(b"a=TRUE", false), json!({"a": true}));
|
|
290
|
+
assert_eq!(parse_query_string_to_json(b"a=False", false), json!({"a": false}));
|
|
291
|
+
assert_eq!(parse_query_string_to_json(b"a=FALSE", false), json!({"a": false}));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#[test]
|
|
295
|
+
fn parse_query_string_to_json_parses_multiple_values() {
|
|
296
|
+
assert_eq!(
|
|
297
|
+
parse_query_string_to_json(b"a=1&a=2&a=3", true),
|
|
298
|
+
json!({ "a": [1,2,3] })
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
#[test]
|
|
303
|
+
fn parse_query_string_to_json_parses_null() {
|
|
304
|
+
assert_eq!(parse_query_string_to_json(b"a=null", true), json!({ "a": null }));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
#[test]
|
|
308
|
+
fn parse_query_string_to_json_parses_empty_string() {
|
|
309
|
+
assert_eq!(parse_query_string_to_json(b"a=", true), json!({ "a": "" }));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
#[test]
|
|
313
|
+
fn parse_query_string_to_json_parses_empty_string_without_number_parsing() {
|
|
314
|
+
assert_eq!(parse_query_string_to_json(b"a=", false), json!({ "a": "" }));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
#[test]
|
|
318
|
+
fn parse_query_string_to_json_parses_multiple_string_values() {
|
|
319
|
+
assert_eq!(
|
|
320
|
+
parse_query_string_to_json(b"q=foo&q=bar", true),
|
|
321
|
+
json!({ "q": ["foo", "bar"] })
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
#[test]
|
|
326
|
+
fn parse_query_string_to_json_parses_multiple_string_values_with_parse_numbers_false() {
|
|
327
|
+
assert_eq!(
|
|
328
|
+
parse_query_string_to_json(b"q=foo&q=bar", false),
|
|
329
|
+
json!({ "q": ["foo", "bar"] })
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#[test]
|
|
334
|
+
fn parse_query_string_to_json_preserves_order_and_duplicates() {
|
|
335
|
+
assert_eq!(
|
|
336
|
+
parse_query_string_to_json(b"q=foo&q=bar&q=baz", true),
|
|
337
|
+
json!({ "q": ["foo", "bar", "baz"] })
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
assert_eq!(
|
|
341
|
+
parse_query_string_to_json(b"q=foo&q=foo&q=bar", true),
|
|
342
|
+
json!({ "q": ["foo", "foo", "bar"] })
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
#[test]
|
|
347
|
+
fn test_url_encoded_special_chars_in_values() {
|
|
348
|
+
let result = parse_query_string_to_json(b"email=x%40test.com&special=%26%40A.ac", false);
|
|
349
|
+
assert_eq!(
|
|
350
|
+
result,
|
|
351
|
+
json!({
|
|
352
|
+
"email": "x@test.com",
|
|
353
|
+
"special": "&@A.ac"
|
|
354
|
+
})
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
#[test]
|
|
359
|
+
fn test_url_encoded_space() {
|
|
360
|
+
let result = parse_query_string_to_json(b"name=hello%20world", false);
|
|
361
|
+
assert_eq!(result, json!({ "name": "hello world" }));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
#[test]
|
|
365
|
+
fn test_url_encoded_complex_chars() {
|
|
366
|
+
let result = parse_query_string_to_json(b"name=test%26value%3D123", false);
|
|
367
|
+
assert_eq!(result, json!({ "name": "test&value=123" }));
|
|
368
|
+
}
|
|
369
|
+
}
|