const data = "<pre>\x20!=?[\x8D¾\n#+%%41&</pre>\b\b"
Here are some ways to percent-encode the string data, as defined above, in a URL query string. As a goal, the encoded string should be readable by URLSearchParams. Each example is followed by the output I received from the following JS code.
JSON.stringify(new URLSearchParams(location.search).get('b'))
The expected output is "<pre> !=?[¾\n#+%%41&</pre>\b\b". I defined data in this way since it contains a variety of character types: disallowed in URLs, unreserved in URLs, reserved in URLs, C0 and C1 control codes, relevant delimiters, and non-ASCII characters.
"<pre> !=?[¾\n#+%%41&</pre>\b\b""<pre> !=?[¾\n#+%%41&</pre>\b\b"key=valuepairs, and U+2B (+) which represents U+20. The U+20 present in
data is replaced with U+2B (+) instead of %20."<pre> !=?[¾\n#+%%41&</pre>\b\b""<pre> !=?[¾\n#+%%41&</pre>\b\b"data. The newline U+A (\n) and the final U+8 (\b) are encoded to prevent the basic URL parser from removing them. The number sign U+23 (#) is encoded, since it signals the end of the query part of a URL. Their special usage requires U+26 (&) and U+2B (+) to be encoded, and the second U+25 (%) is encoded as the two characters following it are valid hex digits. Encoding in this way allows characters which are invalid in URLs, XML 1.0, and HTML."<pre> !=?[¾# %A&</pre>""<pre> !=?[¾""<pre> !=?[¾\n#+%%41&</pre>\b\b"