- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Frist!
Admin
What happens if one query parameter is a substring of another parameter?
Addendum 2023-04-13 08:31: Should have specifially said prefix, not just any substring in general.
Admin
Trihd.
Admin
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.
Admin
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.
Admin
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.