Skip to content

Commit

Permalink
Fix parsing of quoted strings
Browse files Browse the repository at this point in the history
On perl versions < 5.18 or with specific ccflags, the regex would run very long.

#187
#186
  • Loading branch information
perlpunk committed Mar 21, 2018
1 parent 4220ed0 commit e6e290f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions lib/YAML/Loader.pm
Expand Up @@ -526,33 +526,43 @@ sub _parse_inline_seq {
# Parse the inline double quoted string.
sub _parse_inline_double_quoted {
my $self = shift;
my $node;
# https://rt.cpan.org/Public/Bug/Display.html?id=90593
if ($self->inline =~ /^"((?:(?:\\"|[^"]){0,32766}){0,32766})"\s*(.*)$/) {
$node = $1;
$self->inline($2);
$node =~ s/\\"/"/g;
}
else {
$self->die('YAML_PARSE_ERR_BAD_DOUBLE');
my $inline = $self->inline;
if ($inline =~ s/^"//) {
my $node = '';

while ($inline =~ s/^(\\.|[^"\\]+)//) {
my $capture = $1;
$capture =~ s/^\\"/"/;
$node .= $capture;
last unless length $inline;
}
if ($inline =~ s/^"//) {
$self->inline($inline);
return $node;
}
}
return $node;
$self->die('YAML_PARSE_ERR_BAD_DOUBLE');
}


# Parse the inline single quoted string.
sub _parse_inline_single_quoted {
my $self = shift;
my $node;
if ($self->inline =~ /^'((?:(?:''|[^']){0,32766}){0,32766})'\s*(.*)$/) {
$node = $1;
$self->inline($2);
$node =~ s/''/'/g;
}
else {
$self->die('YAML_PARSE_ERR_BAD_SINGLE');
my $inline = $self->inline;
if ($inline =~ s/^'//) {
my $node = '';
while ($inline =~ s/^(''|[^']+)//) {
my $capture = $1;
$capture =~ s/^''/'/;
$node .= $capture;
last unless length $inline;
}
if ($inline =~ s/^'//) {
$self->inline($inline);
return $node;
}
}
return $node;
$self->die('YAML_PARSE_ERR_BAD_SINGLE');
}

# Parse the inline unquoted string and do implicit typing.
Expand Down

0 comments on commit e6e290f

Please sign in to comment.