Project

General

Profile

Actions

Bug #10893

closed

String#chomp (and chomp!) with a UTF-8 record separator results in Encoding::CompatibilityError

Added by Eregon (Benoit Daloze) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-02-23 trunk 49693) [x86_64-linux]
[ruby-core:68258]

Description

Reproducing code:

$/="\n".encode("UTF-8"); p "abc\r\n".encode("utf-32be").chomp

The encode to UTF-8 is to make sure the encoding is consistent across versions, but in recent rubies it is not necessary to trigger the bug.

ruby 2.3.0dev (2015-02-23 trunk 49693) [x86_64-linux]
-e:1:in `chomp': incompatible character encodings: UTF-32BE and UTF-8 (Encoding::CompatibilityError)
	from -e:1:in `<main>'


ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
-e:1:in `chomp': incompatible character encodings: UTF-32BE and UTF-8 (Encoding::CompatibilityError)
	from -e:1:in `<main>'

ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
"abc"
Actions #1

Updated by nobu (Nobuyoshi Nakada) about 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r49706.


string.c: smart chomp

  • string.c (chompped_length): enable smart chomp for all non-dummy
    encoding strings, not only default_rs.
    [ruby-core:68258] [Bug #10893]

Updated by naruse (Yui NARUSE) about 9 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: DONE

ruby_2_2 r49718 merged revision(s) 49706.

Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: DONE to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE
% ruby -ve '$/="\n".encode("UTF-8"); p "abc\r\n".encode("utf-32be").chomp'
ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-darwin13.4.0]
"abc"
% ruby -ve '$/="\n".encode("UTF-8"); p "abc\r\n".encode("utf-32be").chomp'
ruby 2.1.5p299 (2015-02-19 revision 49651) [x86_64-darwin13.0]
"abc"
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0