Project

General

Profile

Actions

Bug #21101

closed

Encoding::CompatibilityError when using String#strip

Added by jpeterburs (Jonas Peterburs) 2 days ago. Updated about 21 hours ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:120841]

Description

When opening an ISO 8859-1 encoded file containing a German letter (e.g. ö), then parsing through each line and stripping whitespace using either rstrip or strip it raises an Error ( lstrip seams fine; I'd assume it skips stripping when there isn't any whitespace in front of the string).

File.open('test.dat').each_line { |line| line.strip } # raises Encoding::CompatibilityError

I've tried this with multiple ruby versions.

It was working as expected in these versions:

  • 2.7.8
  • 3.0.0
  • 3.0.7
  • 3.1.0
  • 3.1.1
  • 3.1.2
  • 3.1.3
  • 3.1.4
  • 3.1.5
  • 3.1.6

And it didn't work in these:

  • 3.2.0
  • 3.2.1
  • 3.2.2
  • 3.2.3
  • 3.2.4
  • 3.2.5
  • 3.2.6
  • 3.3.6
  • 3.3.7

I didn't find anything in the Patch notes of ruby 3.2.0 about the changed behavior.

Did I miss something?


Files

test.dat (142 Bytes) test.dat A latin1 encoded file with German ö letter jpeterburs (Jonas Peterburs), 01/30/2025 11:44 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18931: Inconsistent handling of invalid codepoints in String#lstrip and String#rstripClosedActions
Actions #1

Updated by nobu (Nobuyoshi Nakada) 2 days ago

  • Related to Bug #18931: Inconsistent handling of invalid codepoints in String#lstrip and String#rstrip added

Updated by nobu (Nobuyoshi Nakada) 2 days ago

See https://bugs.ruby-lang.org/issues/18931.

You can add encoding: Encoding::ISO_8859_1 keyword argument to tell the expected encoding.

Updated by jpeterburs (Jonas Peterburs) 2 days ago

Thank you very much for the quick answer, that seems to have resolved my problem.

Actions #4

Updated by byroot (Jean Boussier) about 21 hours ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0