From a5e738b18fb6a191e5655904aa4ba679d7e0731d Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 22 Mar 2024 23:27:53 +0900 Subject: [PATCH] Revert "parser: simplify :skip_lines implementation" This reverts commit c2cc9841cecf833b5c4132c6d1ad764cf426b7a2. This may cause invalid parse result. --- lib/csv/parser.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index f62c398a..d7fcd10e 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -901,15 +901,18 @@ def build_scanner def skip_needless_lines return unless @skip_lines - @scanner.keep_start - @scanner.each_line(@row_separator) do |line| - line << @row_separator if parse_row_end - break unless skip_line?(line) - @lineno += 1 - @scanner.keep_drop + until @scanner.eos? @scanner.keep_start + line = @scanner.scan_all(@not_line_end) || "".encode(@encoding) + line << @row_separator if parse_row_end + if skip_line?(line) + @lineno += 1 + @scanner.keep_drop + else + @scanner.keep_back + return + end end - @scanner.keep_back end def skip_line?(line)