
|
If you were logged in you would be able to see more operations.
|
|
|
|
Original Estimate:
|
Unknown
|
Remaining Estimate:
|
Unknown
|
Time Spent:
|
Unknown
|
|
|
Luke Closs reports: "I found a bug in your get_string_array function where 'one, two, three' wouldn't return 'three'. My new routine just uses split instead of the loop you had, but you may wish to check the other languages' drivers to see if they have the bug as well."
He suggests this code:
sub get_string_array {
my $self = shift;
return map { s#\\([\\,])#$1#g; $_ } # strip extra \'s
# split on not a '\', then a ','
# uses a zero-width positive look-behind assertion
split /(?<=[^\\]),/, $self->get_string(@_);
}
|
|
Description
|
Luke Closs reports: "I found a bug in your get_string_array function where 'one, two, three' wouldn't return 'three'. My new routine just uses split instead of the loop you had, but you may wish to check the other languages' drivers to see if they have the bug as well."
He suggests this code:
sub get_string_array {
my $self = shift;
return map { s#\\([\\,])#$1#g; $_ } # strip extra \'s
# split on not a '\', then a ','
# uses a zero-width positive look-behind assertion
split /(?<=[^\\]),/, $self->get_string(@_);
}
|
Show » |
|
I had rejected using a lookbehind splitter here because you can't be sure that a comma is escaped simply because there is a backslash before it. Consider the following cases:
1 one,two -> "one","two"
2 one\,two -> "one,two"
3 one\\,two -> "one\","two"
4 one\\\,two -> "one\,two"
5 one\\\\,two -> "one\\","two"
A lookbehind splitter will fail case 3, believing that the comma should not split the sequence even though the preceding backslash is itself escaped.
Similarly, a lookbehind that itself contains a negative lookbehind for one backslash will fail case 4. What would be needed is a variable-length lookbehind, which is illegal in most regex syntaxes; hence I used a simple parser.
The fix is a one-line fix (to push the last token onto the array before returning); I'd remembered to do this in Java and C#, but this bug was indeed affecting python and ruby as well. I've fixed them there.