Problems? Is your data what you think it is? | |
PerlMonks |
Finding bugs that lead to bigger bugsby submersible_toaster (Chaplain) |
on Mar 14, 2006 at 06:59 UTC ( [id://536486]=perlmeditation: print w/replies, xml ) | Need Help?? |
Working with a product today (not mentioning names), I discovered the output from one of it's provided 'helpers' was not as documented, with additional backslashes appearing in the output where none occured in the input. A fair assumption then that this program was attempting to escape the values. Diving into the code I discovered a likely clause which first struck me as being.
My biggest gripe with this fragment of code is the mutating of $val in the condition. It seems very wrong to me. As a quick fix I modified the substitution regex to what I believed was intended. if ( $val =~ s/(["\\])/\\$1/g or ..... Excellent, my short test program is now escaping things rather than replacing double-quotes with backslashes. Let's apply these changes to the vendor code - it appears in two places so I change them both. No luck, some of the output is now correct, but mysteriously , some is not. Uh oh. The quoting is correct but some is quoted, the quotes escaped , then quoted again. I knew that mutator was evil.
Why Why Why! - I'll tell you why , $val is a scalar stored in an array. A reference to this array is used twice, in a foreach like so A quick smattering of warns confirms the bad news And that's where the story ends. I'd be intrigued to hear other peoples experiences of being ambushed by a bigger bug whilst fixing another. I can't believe it's not psellchecked
Back to
Meditations
|
|