Closed MasterInQuestion closed 1 year ago
Looks to be the default behavior of Javascript unfortunately. Not sure if it can be overridden easily.
new URL('https://regex101.com/?regex=\w+').searchParams.get('regex') // "\w "
Unrelated with JavaScript. It's the server's interpretation of the request query: which may be implemented arbitrarily.
For more info: https://pastebin.com/raw/YTi5UzLq
@MasterInQuestion I just showed you the implementation.
Hmm... My apologies. Didn't realize that the interoperation of this parameter is implemented entirely on front-end with JavaScript.
This RegEx should work: /[?&]regex=([^&]*)/ [1] (matching against the full URL string, take only "$1") [1] Ideally which should be /[?&]regex=\K[^&]*/ [Note 1], but JavaScript has compatibility issues with lookbehind. . Then filter the result with "decodeURIComponent". \ \ === Further reading ===
[ [Note 1] More ideally this should be implemented in 2-pass, and typically gathering all parameters at once: |1| /\?([^=]+)(?:=([^&]*))?/ && |2| /&([^=]+)(?:=([^&]*))?/g [ This should start from where |1| ends. ]
For Just-in-Time compiled implementations (like JavaScript): the compilation cost should also be taken into performance consideration. ]
For example, [ https://regex101.com/?regex=+ ] should interpret to "+" (Plus Sign) (U+002B, 0x2B, +) instead of " " (Space) (U+0020, 0x20,  ).
Interpreting literal "+" as " " in certain request parameters is typically only expected for search queries.
Related: #414 (already fixed)