Head->Desk Monday
-
Came across this:
// Build the query string StringBuilder sb = new StringBuilder(); bool first = true; foreach (string ParamName in QueryStringVals.Keys) { if (first) { sb.Append("?" + ParamName + "=" + QueryStringVals[ParamName]); } else { sb.Append("&" + ParamName + "=" + QueryStringVals[ParamName]); } }
-
That looks familiar, almost as if I might have written that.
Oh I see the WTF now. First is never toggled to false.
Frist is always frist! Even when it's not frist.
-
And any characters in the query string that need quoting aren't being quoted…
-
And any characters in the query string that need quoting aren't being quoted…
Not necessarily a WTF, it's possible that never happens in this system.
-
And any characters in the query string that need quoting aren't being quoted…
The parameter values are already URL-encoded.
-
Oh I see the WTF now. First is never toggled to false.
Why use a toggle/flag? Just do a Regex search each time through the loop to see if it starts with a ? character...
Filed Under: You laugh, but I've seen it
-
Meh.
StringgBuilder sb = new StringBuilder(); foreach (string ParamName in QueryStringVals.Keys) { sb.AppendFormat("{0}{1}={2}", ((sb.Length == 0) ? "?" : "&"), ParamName, QueryStringVals[ParamName]); }
-
You know I was kidding right?
-
Yup. I just posted my actual solution.
Your solution is obviously wrong, since it doesn't contain XML.
-
Does the solution contain XML that describes find/replace changes of raw PHP in the files that are the application designed to parse said XML?
-
The PHP is stored in SQL and then exec'd in script.
-
Ah but there's the thing. You're talking about a hypothetical monstrosity. I'm talking about one that already exists.
And there's an easter egg in it where it actually makes SQL queries to concatenate a string, too.
-
And there's an easter egg in it where it actually makes SQL queries to concatenate a string, too.
I had a piece of code sent to me once as an example of the type of work that would be expected of me. It was a giant blob of PL/SQL that generated a valid .doc
I SWEAR I saved it somewhere, but no amount of grepping managed to dig it out :(
-
Nice.
Btw, I just submitted the easter egg I remembered to CodeSOD if you're curious on how not to build a one line string.
-
I think it would be more efficient to just concatenate
"&", ParamName, "=", QueryStringVals[ParamName]
Then, outside the loop, replace the first character with "?" and you're done.
-
If constructing URLs is the bottleneck in your application, your application is probably a URL constructor.
-
Yeah, I could see a .TrimStart("&") in there.
-
The worst part about this issue is that it's in an app that was re-written to do the exact same things in a different JavaScript framework with different CSS, and it broke a ton of things like this. I'm probably going to divert any programming I have to do on that project to another person. The whole app is architected incorrectly, it suffers from something similar to adding two numbers in JavaScript.