This pull request fixes the issue I described in: https://bugs.ruby-lang.org/issues/8560
Basically, skip_lines takes any object that responds to match and passes in each line of the csv as an argument to match. But when skip_lines is a string, string#match converts it's argument to a Regexp. In our case, that argument is each line in the CSV. So each line gets converted to a Regexp one at a time.
It is very unexpected behavior for each line in the CSV to act as a Regexp. And in many cases, it will cause an error similar to:
2.0.0-p247 :001 > "test".match "#("
RegexpError: end pattern with unmatched parenthesis: /#(/
from (irb):1:in `match'
from /home/kyle/.rvm/rubies/ruby-2.0.0-p247/bin/irb:12:in `<main>'
Forced to make the choice between converting skip_lines to a Regexp if it's a String and converting each line in the CSV to a Regexp, I've chosen the former.
This patch is perfect and ready to apply. Can we merge it here or does it need to be done via Subversion?
It needs to be committed via subversion.
The expected value should come first to assert_equal.
* lib/csv.rb: If skip_lines is set to a String, convert it to a Regexp
to prevent the alternative, which is that each line in the CSV gets
converted to a Regexp when calling skip_lines#match.
Thanks guys. I've fixed the assertions to have expectations come first and I've generated a patch that I've attached to the original issue in Redmine.
I've applies the patch. We can close this pull request.
@JEG2 in the future you can close pull requests by including a comment like this the commit message: