Actions
Feature #12926
closed-l flag for line end processing should use chomp! instead of chop!
Description
Using chop!
can mess up the final line of input because it may not end in a line-end character.
printf a\\nb\\nc | ruby -lne 'p $_'
"a"
"b"
""
$ printf a\\nb\\nc\\n | ruby -lne 'p $_'
"a"
"b"
"c"
Using chomp!
works correctly in both cases.
$ printf a\\nb\\nc | ruby -ne '$_.chomp!; p $_'
"a"
"b"
"c"
$ printf a\\nb\\nc\\n | ruby -ne '$_.chomp!; p $_'
"a"
"b"
"c"
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
I'd consider it a bug.
Updated by matz (Yukihiro Matsumoto) almost 8 years ago
- Assignee set to nobu (Nobuyoshi Nakada)
OK, accepted
This is because -l
is older than chomp
.
Matz.
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
- Status changed from Open to Closed
Applied in changeset r57373.
parse.y: chomp by -l
- parse.y (rb_parser_while_loop): should chomp but not chop by -l
option. [ruby-core:78099] [Bug #12926]
Actions
Like0
Like0Like0Like0