History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: SRC-42
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dan Fabulich
Reporter: Dan Fabulich
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Selenium Remote Control

get_string_array doesn't return final element

Created: 18/Apr/06 07:21 PM   Updated: 18/Nov/08 09:23 AM
Component/s: Client Driver - Python, Client Driver - Ruby, Client Driver - Perl
Affects Version/s: 0.8.0
Fix Version/s: 0.8.0

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
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(@_);
}


 All   Comments   Work Log   Change History      Sort Order:
Dan Fabulich - 18/Apr/06 07:52 PM
Fixed in revision 1045.

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.