From f26bdc9109abffc86ea78bb85cf3504a771d17ad Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Sat, 9 Jul 2022 18:02:44 -0700 Subject: feat: non-strict mode replaces invalid UTF-8 (#62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes non-strict mode percent-decode utf-8 lossily. This means that invalid UTF-8 percent encoded sequences, such as `%E9`, are decoded as the unicode replacement character (� `U+FFFD`). Refs: https://github.com/samscott89/serde_qs/issues/43 --- src/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 96ce141..9df0f15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,9 +75,14 @@ //! ## Strict vs Non-Strict modes //! //! `serde_qs` supports two operating modes, which can be specified using -//! [`Config`](struct.Config.html), and is all about how `serde_qs` handles square brackets. -//! -//! Techncially, square brackets should be encoded in URLs as `%5B` and `%5D`. +//! [`Config`](struct.Config.html). +//! Strict mode has two parts: +//! - how `serde_qs` handles square brackets +//! - how `serde_qs` handles invalid UTF-8 percent decoded characters +//! +//! ### Square Brackets +//! +//! Technically, square brackets should be encoded in URLs as `%5B` and `%5D`. //! However, they are often used in their raw format to specify querystrings //! such as `a[b]=123`. //! @@ -96,6 +101,14 @@ //! automatically encodes the brackets. But care must be taken to avoid //! using keys with square brackets in them, or unexpected things can //! happen. +//! +//! ### Invalid UTF-8 Percent Encodings +//! +//! Sometimes querystrings may have percent-encoded data which does not decode +//! to UTF-8. In some cases it is useful for this to cause errors, which is how +//! `serde_qs` works in strict mode (the default). Whereas in other cases it +//! can be useful to just replace such data with the unicode replacement +//! character (� `U+FFFD`), which is how `serde_qs` works in non-strict mode. //! //! ## Flatten workaround //! -- cgit v1.2.3