Copy link to clipboard
Copied
Hello, everyone.
A co-worker asked for a second set of eyes regarding an issue he was having. Pulling text from a database, said text was put in a loop with several replaceNoCase() statements, then displayed as an attribute of an anchor tag; so, obviously, one of the replacements is the double quote. Every version of the double quote that we could think of was part of the loop, so it was looking for the standard quote, MS smart quotes, etc., and even included chr(34), all to be replaced with ".
Except for some strange reason, every other replace was working, but the " was still appearing and breaking the anchor attributes.
After a while of trying to understand what was happening, my co-worker (as a test) set the last line of the loop giving the variable an incremented name (ie, "thisVar" became "thisVar1") and replaced chr(34) with " and then output the new variable name. Voila. The replacement worked.
What happened? Why was every other replace working? And why did it work when the variable was renamed??
Scratchin' my head on this one.
Thank you,
^_^
Copy link to clipboard
Copied
It's very difficult to say anything sensible about this without you posting some code which demonstrates what you're talking about.
--
Adam
Copy link to clipboard
Copied
Unfortunately, this is not feasible. Our dev systems are isolated from the internet, and I cannot copy/paste the code. It's about 30 lines of replaceNoCase().
^_^
Copy link to clipboard
Copied
What, you can't sneakernet the file from there to a machine you can copy and paste from?
Anyway, sounds like you've sorted it.
--
Adam
Copy link to clipboard
Copied
Adam Cameron. wrote:
What, you can't sneakernet the file from there to a machine you can copy and paste from?
Anyway, sounds like you've sorted it.
--
Adam
No burning permission for CDs, no flash drives, no nothing.
^_^
Copy link to clipboard
Copied
I'd troubleshoot with a short string that contains a double quote. something like a"b.
Before and after each replace, I'd output the ascii code of each character in my variable. That information would probly help me figure it out.
Copy link to clipboard
Copied
He's given up on troubleshooting, since it was resolved by changing the variable name on that one specific (and last) replaceNoCase(). I was just posting the question because I would like to understand what went wrong and why.
But thank you to you and Adam for responding.
^_^
Copy link to clipboard
Copied
I, too, am curious. I am sure there is a simple explanation.
For example, you might have forgotten to set the 4th attribute of the replaceNoCase function to "all". Then if Coldfusion encountered two of more consecutive double-quotes, it would have replaced just the first one.
Added later: I have assumed you enclosed the text from the database with single-quotes, before doing the replacement.
Copy link to clipboard
Copied
No, all of the replaceNoCase() instances have all four attributes, and the last one for all of them is indeed "all". And the data is enclosed within single quotes.
^_^