Commit 3306116b authored by Mattias Päivärinta's avatar Mattias Päivärinta
Browse files

PDTT-420 - Allow single trailing space after empty field

parent 4e88c93c
......@@ -215,9 +215,6 @@ sub next_line {
# Strip trailing space
$line =~ s/( *)$//;
my $trail_space = $1;
if ( length $trail_space > 0 ) {
push @errors, sprintf( "line %d: trailing space not allowed", $self->{_line_no} );
}
# Match token type
my $token;
......@@ -251,6 +248,10 @@ sub next_line {
my @translations = split '/', ( $2 || '' );
my $value = $3;
if ( !defined $value ) {
$trail_space =~ s/ $//;
}
$token = 'field';
$token_value = [ $key, \@translations, $value ];
}
......@@ -265,6 +266,10 @@ sub next_line {
$token_value = $line;
}
if ( length $trail_space > 0 ) {
push @errors, sprintf( "line %d: trailing space not allowed", $self->{_line_no} );
}
$self->{_lookahead_line} = $line;
$self->{_lookahead} = [ $token, $token_value, \@errors ];
return;
......
......@@ -209,16 +209,38 @@ subtest 'Leading space' => sub {
};
subtest 'Trailing space' => sub {
plan tests => 4;
plan tests => 3;
my $lexer = PDT::TS::Whois::Lexer->new("Key: Value with trailing space \r\n");
my $lexer = PDT::TS::Whois::Lexer->new("Key: Value with trailing space \r\nKey: \r\nKey: \r\n");
my ($token, $value, $errors) = $lexer->peek_line();
is($token, 'field', 'Should recognize field with stripped value');
eq_or_diff($value, ['Key', [], 'Value with trailing space'], 'Should recognize field with stripped value');
is(scalar @$errors, 1, 'Should detect an error');
like($errors->[0], qr/trailing space/i, 'Should complain about trailing space');
$lexer->next_line();
subtest 'Strip field value' => sub {
plan tests => 4;
my ($token, $value, $errors) = $lexer->peek_line();
is($token, 'field', 'Should report correct token');
eq_or_diff($value, ['Key', [], 'Value with trailing space'], 'Should report correct token value');
is(scalar @$errors, 1, 'Should detect an error');
like($errors->[0], qr/trailing space/i, 'Should complain about trailing space');
$lexer->next_line();
};
subtest 'Empty field with single trailing space' => sub {
plan tests => 3;
my ($token, $value, $errors) = $lexer->peek_line();
is($token, 'field', 'Should report correct token');
eq_or_diff($value, ['Key', [], undef], 'Should report correct token value');
eq_or_diff($errors, [], 'Should report no error');
$lexer->next_line();
};
subtest 'Empty field with too much trailing space' => sub {
plan tests => 4;
my ($token, $value, $errors) = $lexer->peek_line();
is($token, 'field', 'Should report correct token');
eq_or_diff($value, ['Key', [], undef], 'Should report correct token value');
is(scalar @$errors, 1, 'Should detect an error');
like($errors->[0], qr/trailing space/i, 'Should complain about trailing space');
$lexer->next_line();
};
};
subtest 'Pattern matching' => sub {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment