ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "k0kubun (Takashi Kokubun) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "k0kubun (Takashi Kokubun)" <noreply@ruby-lang.org>
Subject: [ruby-core:120686] [Ruby master Bug#20924] IO#readline ignores the limit argument when the encoding is UTF-32LE and the limit would split a character
Date: Wed, 15 Jan 2025 01:53:48 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-111509.20250115015346.692@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20924.20241129160708.692@ruby-lang.org>

Issue #20924 has been updated by k0kubun (Takashi Kokubun).

Backport changed from 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: DONE

ruby_3_3 commit:00147cbab567b05b8a4137875bbda341ef704760 merged revision(s) commit:e90b447655dd39ad1eb645cdaae450efd605db00.

----------------------------------------
Bug #20924: IO#readline ignores the limit argument when the encoding is UTF-32LE and the limit would split a character
https://bugs.ruby-lang.org/issues/20924#change-111509

* Author: javanthropus (Jeremy Bopp)
* Status: Closed
* ruby -v: ruby 3.4.0dev (2024-11-28T12:38:16Z master 3af1a04741) +PRISM [x86_64-linux]
* Backport: 3.1: REQUIRED, 3.2: DONE, 3.3: DONE
----------------------------------------
```ruby
require 'tempfile'

Tempfile.open(binmode: true, encoding: 'utf-32le') do |f|
  f.write('0123456789')
  f.rewind

  # A limit that would truncate a character becomes completely ignored
  f.readline(3).bytesize  # => 40; should be 4
end

Tempfile.open(binmode: true, encoding: 'utf-32le') do |f|
  f.write('0123456789')
  f.rewind

  # A limit on character boundaries is respected
  f.readline(4).bytesize  # => 4
end

Tempfile.open(encoding: 'utf-8:utf-32le') do |f|
  f.write('0123456789')
  f.rewind

  # A limit that would truncate a character becomes completely ignored
  f.readline(3).bytesize  # => 40; should be 4
end

Tempfile.open(encoding: 'utf-8:utf-32le') do |f|
  f.write('0123456789')
  f.rewind

  # A limit on character boundaries is respected
  f.readline(4).bytesize  # => 4
end
```

This doesn't happen with UTF-32BE.  This also doesn't happen in Ruby 3.3, but it does happen in 3.4-dev and Ruby 3.0 - 3.2.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

      parent reply	other threads:[~2025-01-15  1:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 16:07 [ruby-core:120058] " javanthropus (Jeremy Bopp) via ruby-core
2024-11-29 16:35 ` [ruby-core:120059] " javanthropus (Jeremy Bopp) via ruby-core
2024-12-15  9:33 ` [ruby-core:120248] " nagachika (Tomoyuki Chikanaga) via ruby-core
2025-01-15  1:53 ` k0kubun (Takashi Kokubun) via ruby-core [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-111509.20250115015346.692@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).