@@ -446,6 +446,7 @@ def prepare_strip
446
446
@strip = @options [ :strip ]
447
447
@escaped_strip = nil
448
448
@strip_value = nil
449
+ @rstrip_value = nil
449
450
if @strip . is_a? ( String )
450
451
case @strip . length
451
452
when 0
@@ -460,13 +461,16 @@ def prepare_strip
460
461
if @quote_character
461
462
@strip_value = Regexp . new ( @escaped_strip +
462
463
"+" . encode ( @encoding ) )
464
+ @rstrip_value = Regexp . new ( @escaped_strip +
465
+ "+\\ z" . encode ( @encoding ) )
463
466
end
464
467
@need_robust_parsing = true
465
468
elsif @strip
466
469
strip_values = " \t \f \v "
467
470
@escaped_strip = strip_values . encode ( @encoding )
468
471
if @quote_character
469
472
@strip_value = Regexp . new ( "[#{ strip_values } ]+" . encode ( @encoding ) )
473
+ @rstrip_value = Regexp . new ( "[#{ strip_values } ]+\\ z" . encode ( @encoding ) )
470
474
end
471
475
@need_robust_parsing = true
472
476
end
@@ -561,9 +565,6 @@ def prepare_unquoted
561
565
unless @liberal_parsing
562
566
no_unquoted_values << @escaped_quote_character
563
567
end
564
- if @escaped_strip
565
- no_unquoted_values << @escaped_strip
566
- end
567
568
@unquoted_value = Regexp . new ( "[^" . encode ( @encoding ) +
568
569
no_unquoted_values +
569
570
"]+" . encode ( @encoding ) )
@@ -939,6 +940,7 @@ def parse_column_value
939
940
if @liberal_parsing
940
941
quoted_value = parse_quoted_column_value
941
942
if quoted_value
943
+ @scanner . scan_all ( @strip_value ) if @strip_value
942
944
unquoted_value = parse_unquoted_column_value
943
945
if unquoted_value
944
946
if @double_quote_outside_quote
@@ -986,6 +988,9 @@ def parse_unquoted_column_value
986
988
end
987
989
end
988
990
value . gsub! ( @backslash_quote_character , @quote_character ) if @backslash_quote
991
+ if @rstrip_value
992
+ value . gsub! ( @rstrip_value , "" )
993
+ end
989
994
value
990
995
end
991
996
0 commit comments