@@ -446,6 +446,7 @@ def prepare_strip
446446 @strip = @options [ :strip ]
447447 @escaped_strip = nil
448448 @strip_value = nil
449+ @rstrip_value = nil
449450 if @strip . is_a? ( String )
450451 case @strip . length
451452 when 0
@@ -460,13 +461,16 @@ def prepare_strip
460461 if @quote_character
461462 @strip_value = Regexp . new ( @escaped_strip +
462463 "+" . encode ( @encoding ) )
464+ @rstrip_value = Regexp . new ( @escaped_strip +
465+ "+\\ z" . encode ( @encoding ) )
463466 end
464467 @need_robust_parsing = true
465468 elsif @strip
466469 strip_values = " \t \f \v "
467470 @escaped_strip = strip_values . encode ( @encoding )
468471 if @quote_character
469472 @strip_value = Regexp . new ( "[#{ strip_values } ]+" . encode ( @encoding ) )
473+ @rstrip_value = Regexp . new ( "[#{ strip_values } ]+\\ z" . encode ( @encoding ) )
470474 end
471475 @need_robust_parsing = true
472476 end
@@ -561,9 +565,6 @@ def prepare_unquoted
561565 unless @liberal_parsing
562566 no_unquoted_values << @escaped_quote_character
563567 end
564- if @escaped_strip
565- no_unquoted_values << @escaped_strip
566- end
567568 @unquoted_value = Regexp . new ( "[^" . encode ( @encoding ) +
568569 no_unquoted_values +
569570 "]+" . encode ( @encoding ) )
@@ -939,6 +940,7 @@ def parse_column_value
939940 if @liberal_parsing
940941 quoted_value = parse_quoted_column_value
941942 if quoted_value
943+ @scanner . scan_all ( @strip_value ) if @strip_value
942944 unquoted_value = parse_unquoted_column_value
943945 if unquoted_value
944946 if @double_quote_outside_quote
@@ -986,6 +988,9 @@ def parse_unquoted_column_value
986988 end
987989 end
988990 value . gsub! ( @backslash_quote_character , @quote_character ) if @backslash_quote
991+ if @rstrip_value
992+ value . gsub! ( @rstrip_value , "" )
993+ end
989994 value
990995 end
991996
0 commit comments