CC: | RGiersig [...] cpan.org |
Subject: | Expect dies if a raw string starts with an "-" (dash character) |
If i ask expect to match a raw string that has a "-" in the beginning,
the code bellow will assume it is an option string, and if it doesn't
find a matching option, expect() croaks with "Unknown option" message.
Example, if the raw pattern is:
$string = '-bash: line 4: l: command not found\n';
And i try:
$exp->expect(1, $string);
That line above will croak "Unknown option -bash: line 4: l: command not
found".
So using the syntax for "raw string" is not actually working as
expected, since my raw string is being treated like an option, and not
as a raw string.
The bugged code is bellow:
# not a ref, is an option or raw pattern
if (substr($parm, 0, 1) eq '-') {
# it's an option
print STDERR ("expect(): handling option '$parm'...\n")
if $Expect::Debug;
if ($parm eq '-i') {
# first add collected patterns to object list
if (scalar(@$curr_list)) {
push @object_list, $curr_list if not exists $patterns{"$curr_list"};
push @{$patterns{"$curr_list"}}, @pattern_list;
@pattern_list = ();
}
# now put parm(s) into current object list
if (ref($_[0]) eq 'ARRAY') {
$curr_list = shift;
} else {
$curr_list = [ shift ];
}
} elsif ($parm eq '-re'
or $parm eq '-ex') {
if (ref($_[1]) eq 'CODE') {
push @pattern_list, [ $parm_nr, $parm, shift, shift ];
} else {
push @pattern_list, [ $parm_nr, $parm, shift, undef ];
}
$parm_nr++;
} else {
croak ("Unknown option $parm");
}
Thank you,
bruno