Skip to content

Commit

Permalink
made unquoted values not trim by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Aug 20, 2009
1 parent 5e8e0ba commit 2a05957
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/Text/CSV.pm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
grammar Text::CSV::Line {
rule TOP { ^ <value> ** ',' $ }
rule value {
regex TOP { ^ <value> ** ',' $ }
regex value {
| <pure_text>
| \' <single_quote_contents> \'
| \" <double_quote_contents> \"
| \s* \' <single_quote_contents> \' \s*
| \s* \" <double_quote_contents> \" \s*
}
regex single_quote_contents { <pure_text> ** [ <[",]> | \h ] }
regex double_quote_contents { <pure_text> ** [ <[',]> | \h ] }
regex pure_text { [<!before <['",]>> \S]+ }
regex pure_text { [<!before <['",]>> .]+ }
}

class Text::CSV {
Expand Down
10 changes: 7 additions & 3 deletions t/02-commas.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ sub ok_becomes($input, $output, $description = '') {
is_deeply Text::CSV.read($input), $output, $description;
}

ok_becomes q[[[foo,bar,baz
foo, bar, baz
foo, bar, baz]]], [ [<foo bar baz>] xx 3 ], 'a file with commas and spaces';
is_deeply Text::CSV.read(q[[[foo,bar,baz
foo,bar , baz
foo,bar , baz]]]),
[ [<foo bar baz>],
['foo', 'bar ', ' baz'],
['foo', 'bar ', ' baz'] ],
'spaces are not trimmed by default';

done_testing;

Expand Down

0 comments on commit 2a05957

Please sign in to comment.