firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.26k stars 199 forks source link

[Suggestion] "+" should present literally (not translated to " ") in HTTP request parameter interpretation #1993

Closed MasterInQuestion closed 1 year ago

MasterInQuestion commented 1 year ago

    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)

firasdib commented 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 "
MasterInQuestion commented 1 year ago

    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

firasdib commented 1 year ago

@MasterInQuestion I just showed you the implementation.

MasterInQuestion commented 1 year ago

    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. ]