Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/Synergy/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ sub parse_switches ($string) {
# safestr := not-slash+ spaceslash-or-end
# quotestr := '"' ( qchar | not-dquote )* '"' ws-or-end
#
# But for now we'll live without quotestr, because it seems very unlikley to
# come up. -- rjbs, 2019-02-04

while (length $string) {
$string =~ s{\A\s+}{}g;
Expand All @@ -91,12 +89,21 @@ sub parse_switches ($string) {
return (undef, "bogus /command: /$1");
# push @tokens, [ badcmd => $1 ];
# next;
} elsif ($string =~ s{ \A ( [^/]+ ) (\s+/ | $) }{$2}x) {
push @tokens, [ lit => $1 ];
} elsif ($string =~ s{ \A (?<!\\)" ( .*? ) (?<!\\)" }{}x) {
my $val = $1;
$val =~ s/\\"/"/g;

push @tokens, [ lit => $val ];
next;
} elsif ($string =~ s{ \A ( .*? ) (\s+/ | $) }{$2}x) {
my $val = $1;
$val =~ s/\\"/"/g;

push @tokens, [ lit => $val ];
next;
}

return (undef, "incomprehensible input");
return (undef, "incomprehensible input ($string)");
}

my @switches;
Expand Down
62 changes: 50 additions & 12 deletions t/switches.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,39 @@ switches_fail(
"text with no switch",
);

my $B = "\N{REVERSE SOLIDUS}";
{
my $B = "\N{REVERSE SOLIDUS}";

# Later, we will add support for qstrings. -- rjbs, 2019-02-04
switches_fail(
qq{/foo "bar $B/baz" /buz},
"incomprehensible input",
);
my ($switches, $error) = parse_switches(qq{/foo "bar $B/baz" /buz});

# Later, qstrings will allow embedded slashes, and maybe we'll allow them
# anyway if they're inside words. For now, ban them. -- rjbs, 2019-02-04
switches_fail(
qq{/foo hunter/killer program /buz},
"incomprehensible input",
);
is($error, undef, 'no error');

is_deeply(
$switches,
[
[ foo => "bar $B/baz" ],
[ buz => undef ],
],
"quotes",
);
}

{
my $B = "\N{REVERSE SOLIDUS}";

my ($switches, $error) = parse_switches(qq{/foo hunter/killer program /buz});

is($error, undef, 'no error');

is_deeply(
$switches,
[
[ foo => "hunter/killer program" ],
[ buz => undef ],
],
"quotes",
);
}

{
my ($switches, $error) = parse_switches("/f b /b f /foo /bar /foo bar");
Expand All @@ -90,6 +109,25 @@ switches_fail(
[ bar => undef ],
[ foo => 'bar' ],
],
"canonicalize_switches",
);
}

{
my ($switches, $error) = parse_switches(q{/f \\"b\\" /foo /bar "some thing" /baz "some \\" /thing\\"" /meh a/b});

is($error, undef, 'no error');

is_deeply(
$switches,
[
[ f => '"b"' ],
[ foo => undef ],
[ bar => "some thing" ],
[ baz => "some \" /thing\"" ],
[ meh => "a/b" ],
],
"quotes",
);
}

Expand Down