pub struct Config {
pub max_depth: usize,
pub use_form_encoding: bool,
}Expand description
Configuration for serialization and deserialization behavior.
The Config struct allows you to customize how serde_qs handles
querystrings, including nesting depth limits and encoding preferences.
§Nesting Depth
The max_depth parameter controls how deeply nested structures can be.
This is important for preventing denial-of-service attacks from maliciously
crafted inputs with excessive nesting. A max_depth of 0 means no nesting
is allowed (flat key-value pairs only).
Default value: max_depth = 5
use serde_qs::Config;
use std::collections::HashMap;
let config = Config { max_depth: 0, ..Default::default() };
let map: HashMap<String, String> = config.deserialize_str("a[b][c]=1")
.unwrap();
assert_eq!(map.get("a[b][c]").unwrap(), "1");
let config = Config { max_depth: 10, ..Default::default() };
let map: HashMap<String, HashMap<String, HashMap<String, String>>> =
config.deserialize_str("a[b][c]=1").unwrap();
assert_eq!(map.get("a").unwrap().get("b").unwrap().get("c").unwrap(), "1");Fields§
§max_depth: usizeSpecifies the maximum depth key that serde_qs will attempt to
deserialize. Default is 5.
use_form_encoding: boolBy default, serde_qs uses query-string encoding, as defined
in WHATWG.
This is a relatively lax encoding scheme, which does not percent encode many characters (like square brackets).
This makes it possible to encode nested keys like a[b][c]=1
in a relatively compact way. Keys that include square brackets
will get percent-encoded.
e.g. { a: { "[x]": 1 } } will be encoded as a[%5Bx%5D]=1
Note that when using form encoding this means the keys will get percent-encoded twice.
e.g. { a: { "[x]": 1 } } will be encoded as a%5B%255Bx%255D%5D=1
To use form encoding, set this to true.
Alternatively, you can use the default_to_form_encoding Cargo feature
to set this to true by default.
Implementations§
Source§impl Config
impl Config
pub const fn new() -> Self
pub const fn max_depth(self, max_depth: usize) -> Self
pub const fn use_form_encoding(self, use_form_encoding: bool) -> Self
Sourcepub fn deserialize_bytes<'de, T: Deserialize<'de>>(
self,
input: &'de [u8],
) -> Result<T, Error>
pub fn deserialize_bytes<'de, T: Deserialize<'de>>( self, input: &'de [u8], ) -> Result<T, Error>
Deserializes a querystring from a &[u8] using this Config.
Sourcepub fn deserialize_str<'de, T: Deserialize<'de>>(
self,
input: &'de str,
) -> Result<T, Error>
pub fn deserialize_str<'de, T: Deserialize<'de>>( self, input: &'de str, ) -> Result<T, Error>
Deserializes a querystring from a &str using this Config.