Actions
Bug #21101
closedEncoding::CompatibilityError when using String#strip
Bug #21101:
Encoding::CompatibilityError when using String#strip
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
Updated by nobu (Nobuyoshi Nakada) 10 months ago
- Related to Bug #18931: Inconsistent handling of invalid codepoints in String#lstrip and String#rstrip added
Updated by nobu (Nobuyoshi Nakada) 10 months 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) 10 months ago
Thank you very much for the quick answer, that seems to have resolved my problem.
Updated by byroot (Jean Boussier) 10 months ago
- Status changed from Open to Rejected
Actions