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.
if ($val =~ s/["\\]/\\$1/g or $val =~ m/[:\s]/) { $val = qq["$val"]; }
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.
"this was quoted because of whitespace" "\"this was quoted because of whitespace\""
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 newsforeach my $val ( @{$arrayref} ) { # do evil mutating things to $val } foreach my $val ( @{$arrayref} ) { # now do it AGAIN. }
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.FIRST LOOP SCALAR(0x857c5cc) SCALAR(0x857c5d8) SCALAR(0x857c5e4) SCALAR(0x857c5f0) SECOND LOOP SCALAR(0x857c5cc) SCALAR(0x857c5d8) SCALAR(0x857c5e4) SCALAR(0x857c5f0)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding bugs that lead to bigger bugs
by radiantmatrix (Parson) on Mar 14, 2006 at 17:39 UTC | |
by marinersk (Priest) on Mar 16, 2006 at 14:27 UTC | |
Re: Finding bugs that lead to bigger bugs
by marinersk (Priest) on Mar 16, 2006 at 14:21 UTC |