• Fristator (unregistered)


  • (nodebb)

    What happens if one query parameter is a substring of another parameter?

    let queryString = '?admin=true&adminPassword=sTr0ngP455w0rd!';
    let newQueryString = replaceQueryParam('admin', 'false', queryString);

    Addendum 2023-04-13 08:31: Should have specifially said prefix, not just any substring in general.

  • '-- (unregistered)


  • (author) in reply to Eric Ray

    In that specific example, it would work fine- the first time. Subsequent calls would definitely break, though, as it finds the first match and appends the replacements to the end of the string.

  • Sole Purpose Of Visit (unregistered)

    I'd have thought that the only sensible option (back before 2016 or whenever) would be to write your own library, analogous to URLSearchParams. Allow for dictionary access, enumerable access, removal, insertion (presumably always at the end), and make sure to obey Javasript's "I'm almost, but not quite, a FP language" paradigm by constructing an entirely new string where necessary. I'd actually be mildly horrified to learn that such a thing did not exist in a JQuery sort of add-on back then. Only mildly, because this is, after all, Web Programming.

    Then again, it's been something like fifteen years since I've touched the horrid stuff without benefit of Typescript or an equivalent brain sanitizer.

  • Robin (unregistered) in reply to Eric Ray

    I know this was just to illustrate an unrelated point, but I can't resist: if the site puts plaintext passwords in the URL it has bigger problems than bad JS string mangling!

    Returning to the original article, I'm amused that it's written in Typescript, so clearly isn't simply copy-pasted from 2009 or whatever. I guess it's copy pasted with types added to keep the TS compiler/linter happy.

  • nz (unregistered)
    Comment held for moderation.
  • Craig (unregistered)
    Comment held for moderation.

Leave a comment on “Regular Query String”

Log In or post as a guest

Replying to comment #:

« Return to Article