ml.ruby-lang.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

ruby-core

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
ruby-core@ml.ruby-lang.org

November 2026

  • 1 participants
  • 181 discussions
[ruby-core:127563] [Ruby Bug#22595] ObjectSpace::WeakMap#each can yield the same pair twice if compaction happens during iteration
by jhawthorn (John Hawthorn) 17 Nov '26

17 Nov '26
Issue #22595 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #22595: ObjectSpace::WeakMap#each can yield the same pair twice if compaction happens during iteration https://bugs.ruby-lang.org/issues/22595 * Author: jhawthorn (John Hawthorn) * Status: Open * ruby -v: ruby 4.1.0dev (2026-11-16) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- Reproduces on 4.0.9 and master: ```ruby map = ObjectSpace::WeakMap.new key = Object.new map[key] = 1 100.times { |i| map[i] = i } count = 0 map.each do GC.verify_compaction_references(expand_heap: true, toward: :empty) if count == 10 count += 1 end p [map.size, count] # => [101, 102] ``` WeakMap hashes keys by address, so when compaction moves a key `wmap_compact` deletes it and reinserts it at the end of the table, where the `st_foreach` in `#each` reaches it a second time. If that reinsertion rebuilds the table, `#each` stops early instead. The block deleting the current key and then inserting enough to rebuild the table makes it stop early or start over from the first entry. This affects `each`, `each_key`, `each_value` and `inspect`. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:127560] [Ruby Bug#22561] parse.y rejects empty heredocs terminated by `\r\n` (`<<""\r\n\r\n`)
by steviejj (Steven Johnstone) 17 Nov '26

17 Nov '26
Issue #22561 has been reported by steviejj (Steven Johnstone). ---------------------------------------- Bug #22561: parse.y rejects empty heredocs terminated by `\r\n` (`<<""\r\n\r\n`) https://bugs.ruby-lang.org/issues/22561 * Author: steviejj (Steven Johnstone) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- CRuby `parse.y` rejects empty-delimiter heredocs (`<<''`, `<<""`, `<<-''`, `<<~''`) whenever the closing blank terminator line uses `\r\n` (`CRLF`), raising `SyntaxError: can't find string "" anywhere before EOF`—even though `parse.y` accepts non-empty heredocs with `\r\n` (`<<'A'\r\nA\r\n`) as well as empty heredocs with `\n` (`<<''\n\n`). Prism accepts empty heredocs with `\r\n` cleanly. Tested on CRuby `4.0.9` (`--parser=parse.y` vs `--parser=prism`): ```sh # Empty heredoc with CRLF line endings: ruby --parser=prism -e "$(printf 'p <<""\r\n\r\n')" # exits 0, prints "" ruby --parser=parse.y -e "$(printf 'p <<""\r\n\r\n')" # exits 1: can't find string "" anywhere before EOF # Mixed LF opening line + CRLF closing line, and indented variants: for open in "<<''" '<<""' "<<-''" "<<~''"; do printf "p %s\r\n\r\n" "$open" | ruby --parser=prism printf "p %s\r\n\r\n" "$open" | ruby --parser=parse.y done # Non-empty heredoc with CRLF works in both: ruby --parser=parse.y -e "$(printf "p <<'A'\r\nA\r\n")" # exits 0, prints "" -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:127557] [Ruby Bug#22558] parse.y dereferences NULL in evstr2dstr when `%I`/`%W` word concatenation fails on mixed encodings
by steviejj (Steven Johnstone) 17 Nov '26

17 Nov '26
Issue #22558 has been reported by steviejj (Steven Johnstone). ---------------------------------------- Bug #22558: parse.y dereferences NULL in evstr2dstr when `%I`/`%W` word concatenation fails on mixed encodings https://bugs.ruby-lang.org/issues/22558 * Author: steviejj (Steven Johnstone) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ``` ruby -e 'STDOUT.binmode; STDOUT.write("#coding:sjis\n%I \xE2\xE2\xE20\\u0400 ".b)' | ruby --parser=parse.y -c - -:2: invalid multibyte char (Windows-31J) -:2: string literal encodings differ (Windows-31J / UTF-8) -:2: unterminated list meets end of file %I ���0\u0400 ruby: [BUG] Segmentation fault at 0x0000000000000000 ruby 4.0.9 (2026-10-23 revision 3e93b23afc) [arm64-darwin27] -- Crash Report log information -------------------------------------------- See Crash Report log file in one of the following locations: * ~/Library/Logs/DiagnosticReports * /Library/Logs/DiagnosticReports for more details. Don't forget to include the above Crash Report log file in bug reports. -- Control frame information ----------------------------------------------- c:0001 p:0000 s:0003 E:001110 l:y b:---- DUMMY [FINISH] -- Threading information --------------------------------------------------- Total ractor count: 1 Ruby thread count for this ractor: 1 -- Machine register context ------------------------------------------------ x0: 0x0000000102158c10 x1: 0x0000000000000000 x2: 0x000000010214f00e x3: 0x0000000000000001 x4: 0x0000000000000001 x5: 0x0000000000000200 x6: 0x000000000000000a x7: 0xffffffffb00007ff x18: 0x0000000000000000 x19: 0x0000000102158c10 x20: 0x000000000000028e x21: 0x000000016ef892d0 x22: 0x000000016ef88680 x23: 0x000000000000017f x24: 0x000000016ef898ec x25: 0x0000000000000000 x26: 0x0000000000000384 x27: 0x0000000101e14902 x28: 0x0000000101dcbdd2 lr: 0x0000000101ac41c0 fp: 0x000000016ef89ad0 sp: 0x000000016ef88440 -- C level backtrace information ------------------------------------------- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_vm_bugreport+0x374) [0x101bbba2c] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_bug_for_fatal_signal) [0x101a46198] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(sigabrt) [0x101b3816c] /usr/lib/system/libsystem_platform.dylib(_sigtramp+0x38) [0x18bcac144] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(ruby_yyparse) [0x101ac41c0] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(yycompile0) [0x101ad1358] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_suppress_tracing) [0x101bbcfb4] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_parser_compile) [0x101acfba8] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(parser_compile) [0x101b2e328] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_parser_compile_file_path) [0x101b2d38c] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(load_file_internal) [0x101b2a048] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(rb_ec_ensure) [0x101a4e2e8] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(ruby_process_options) [0x101b2939c] /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib(ruby_options) [0x101a4cf20] /opt/homebrew/Cellar/ruby/4.0.9/bin/ruby(main+0x64) [0x100e755a4] -- Other runtime information ----------------------------------------------- * Loaded script: ruby * Ruby Box: disabled * Loaded features: 0 enumerator.so 1 thread.rb 2 fiber.so 3 rational.so 4 complex.so 5 pathname.so 6 ruby2_keywords.rb 7 set.rb 8 /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/enc/encdb.bundle 9 /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/enc/trans/transdb.bundle 10 /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/4.0.0/arm64-darwin27/enc/windows_31j.bundle * Process memory map: 100e88000-100e90000 r-- /opt/homebrew/Cellar/ruby/4.0.9/bin/ruby 100e90000-100e94000 r-- /opt/homebrew/Cellar/ruby/4.0.9/bin/ruby 100e94000-100ed4000 rw- /opt/homebrew/Cellar/ruby/4.0.9/bin/ruby 101260000-10148c000 --- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 10148c000-101570000 rw- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 101570000-101574000 r-- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 101574000-10157c000 rw- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 10158c000-10171c000 --- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 10171c000-101774000 rw- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 101774000-1017f4000 rw- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 102128000-10212c000 --- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 10212c000-10252c000 rw- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 10252c000-102530000 --- /opt/homebrew/Cellar/ruby/4.0.9/lib/libruby.4.0.dylib 131600000-131604000 rw- 7258000000-7258400000 rw- 77aa800000-77aac00000 rw- 77aac00000-77ab000000 rw- 77ab000000-77ab400000 rw- 77ab400000-77ab800000 rw- 77ab800000-77abc00000 rw- [IMPORTANT] Don't forget to include the Crash Report log file under DiagnosticReports directory in bug reports. [1] 18937 done ruby -e | 18938 segmentation fault ruby --parser=parse.y -c - ``` -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:127174] [Ruby Bug#22455] Per-Ractor GC: an idle Ractor costs ~100 KB of memory (17 KB on 4.0)
by matteo.folin@gmail.com (Matteo Folin) 17 Nov '26

17 Nov '26
Issue #22455 has been reported by matteo.folin(a)gmail.com (Matteo Folin). ---------------------------------------- Bug #22455: Per-Ractor GC: an idle Ractor costs ~100 KB of memory (17 KB on 4.0) https://bugs.ruby-lang.org/issues/22455 * Author: matteo.folin(a)gmail.com (Matteo Folin) * Status: Open * ruby -v: ruby 4.1.0preview1 (2026-10-11 master 2d08b5f42f) +PRISM [aarch64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ### Description With the per-Ractor GC, an idle Ractor (blocked in `Ractor.receive`) costs ~101 KB of RSS against ~17 KB on 4.0.7. In our server, a connection's Ractor, with a few threads and a few hundred live objects, went from ~55–80 KB on 4.0 to ~590 KB on 4.1. 25,000 connections need ~15 GB instead of ~1.4 GB. The per-Ractor GC removes our main 4.0 problem: every GC used to stop and mark all Ractors, so its pauses grew with the number of connections. A Ractor per connection is the shape it should favour. At this memory cost, that shape is hard to use for many connections. Is the floor per Ractor (heap pages per size class?) expected, and can it be lowered, for example by allocating a Ractor's pages lazily or sharing partly-used pages? ### Reproduction ```ruby # 4,000 Ractors blocked in Ractor.receive: memory each, and the cost of a full GC. Warning[:experimental] = false def rss_mb = File.read("/proc/self/status")[/VmRSS:\s+(\d+)/, 1].to_i / 1024.0 def now_ms = Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000 GC.start base = rss_mb ractors = Array.new(4000) { Ractor.new { Ractor.receive } } sleep 1 puts format("rss per idle Ractor: %.0f KB", (rss_mb - base) * 1024 / ractors.size) 3.times do t = now_ms GC.start puts format("GC.start: %.1f ms", now_ms - t) end ``` ### Results Same machine as above. | | 4.0.7 | 4.1.0-preview1 | |---|---|---| | RSS per idle Ractor | 17 KB | 101 KB | | `GC.start` (global) with 4,000 idle Ractors | 10–21 ms | 43–141 ms | The global GC's cost matters together with Bug #22454: if global GCs are what reclaims exited Ractors, a server that holds thousands of Ractors pays this pause each time. We saw single global GCs of 0.8–3.9 s, most of it sweeping, in a server holding 2,000–5,000 connection Ractors. -- https://bugs.ruby-lang.org/
2 2
0 0
[ruby-core:127297] [Ruby Bug#22494] Regexp search misses a match when an assertion precedes a leading .*
by mame (Yusuke Endoh) 17 Nov '26

17 Nov '26
Issue #22494 has been reported by mame (Yusuke Endoh). ---------------------------------------- Bug #22494: Regexp search misses a match when an assertion precedes a leading .* https://bugs.ruby-lang.org/issues/22494 * Author: mame (Yusuke Endoh) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- When a regexp starts with an assertion (`^`, `\b`, `(?=...)`, `(?!...)`) followed by `.*`, the search only tries the start position and misses later matches. ```ruby "aab".index(/(?!a).*b/m) #=> nil (expected: 2) "ab\ncb".index(/^.*b/m, 1) #=> nil (expected: 3) "aaaa bx".index(/\b.*x/, 1) #=> nil (expected: 4) ``` @make_now_just found this and wrote the fix. -- https://bugs.ruby-lang.org/
3 3
0 0
[ruby-core:127294] [Ruby Bug#22492] String#rindex misses a match with a leading .* in multiline mode
by mame (Yusuke Endoh) 17 Nov '26

17 Nov '26
Issue #22492 has been reported by mame (Yusuke Endoh). ---------------------------------------- Bug #22492: String#rindex misses a match with a leading .* in multiline mode https://bugs.ruby-lang.org/issues/22492 * Author: mame (Yusuke Endoh) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- `String#rindex` with a regexp starting with `.*` in multiline mode returns `nil` even when there is a match. ```ruby "xab".rindex(/.*b/m) #=> nil (expected: 2) "xab".rindex(/.*b/) #=> 2 ``` @make_now_just found this and wrote the fix. -- https://bugs.ruby-lang.org/
3 3
0 0
[ruby-core:127451] [Ruby Bug#22540] Process.spawn leaves the env, umask, and redirections applied in the parent on Windows when chdir: fails
by jcouball@yahoo.com (James Couball) 17 Nov '26

17 Nov '26
Issue #22540 has been reported by jcouball(a)yahoo.com (James Couball). ---------------------------------------- Bug #22540: Process.spawn leaves the env, umask, and redirections applied in the parent on Windows when chdir: fails https://bugs.ruby-lang.org/issues/22540 * Author: jcouball(a)yahoo.com (James Couball) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- On Windows, when `Process.spawn` is given a `chdir:` directory that is missing or can't be entered, it raises as expected, but the environment, umask, and redirections intended for the child are left applied in the parent process. ```ruby begin Process.spawn({ 'LEAK' => '1' }, 'cmd', '/c', 'exit', chdir: 'no-such-dir', out: File::NULL) rescue SystemCallError nil end p ENV['LEAK'] # => "1" on Windows; nil on Linux and macOS $stdout.puts 'lost' # written to NUL, not the console ``` These related cases also leave the child's settings applied in the parent: - A `chdir:` directory the process can't enter raises `Errno::EACCES`, where a missing one raises `Errno::ENOENT`. Either way, the env, umask, and redirections are left applied in the parent. - `out: 99`, where fd 99 isn't open, raises `Errno::EBADF`. The env and umask are left applied in the parent. The redirections are not, because Ruby fails before it changes the standard streams. - Adding `unsetenv_others: true` to any of these leaves the parent's `ENV` holding only the variables the call passed. - Adding `umask: 0o222` to the example above, or to the `out: 99` case, leaves the parent's umask at 0200, up from 0000, and a file the parent creates afterward is read-only. A spawn with the same `umask:` that fails on a missing program leaves the umask unchanged. The umask cases were run on 3.1.7, 3.4.10, and 4.0.6. Each failure also leaves open the copies `save_redirect_fd` made of the redirected descriptors. A loop of spawns that fail on `chdir:` with `out:` and `err:` redirected stops with `Errno::EMFILE` after about 4,090 iterations. The same loop with a missing program runs 6,000 times without error. Reproduced on the x64-mingw-ucrt builds of 3.1.7, 3.4.2, 3.4.10, and 4.0.6. The code path is unchanged on master at 99fb833, and the same early return is in 2.0.0. Without `fork`, `rb_spawn_process` calls `rb_execarg_run_options(eargp, &sarg, ...)`, which applies env, umask, and fd redirections to the parent and records the old values in `sarg`, and then calls `chdir`. When a step fails, `rb_execarg_run_options` returns -1, and `rb_spawn_process` returns without calling `rb_execarg_run_options(&sarg, NULL, ...)` to restore them. The early return is the `return -1` after the first `rb_execarg_run_options` call in `rb_spawn_process`, in process.c. A missing program fails after that point, so the restore runs and nothing leaks. A possible fix is to restore from `sarg` before returning -1, as the success path does. `sarg` is zeroed at the start of `rb_execarg_run_options` and holds only what was applied before the failure, so restoring it undoes exactly that, and closes the saved descriptors it recorded in `fd_close`. The restore call writes to the same `errmsg` buffer and makes system calls that can change `errno`, so both need saving first, or the exception raised for the original failure changes. This asks that a failed spawn restore the parent as a successful one does: the env, the umask, the redirections, and the saved descriptor copies. The temporary change to the parent during the spawn is not in question. -- https://bugs.ruby-lang.org/
3 2
0 0
[ruby-core:121076] [Ruby master Bug#21142] Lazy enumerator `.each_with_index` ignores `.take(0)` before it
by aaronkison (Aaron Kison) 17 Nov '26

17 Nov '26
Issue #21142 has been reported by aaronkison (Aaron Kison). ---------------------------------------- Bug #21142: Lazy enumerator `.each_with_index` ignores `.take(0)` before it https://bugs.ruby-lang.org/issues/21142 * Author: aaronkison (Aaron Kison) * Status: Open * ruby -v: 3.2.7 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Minimum code to produce problem: ``` class Numbers; def each; 100.times { yield _1 }; end; include Enumerable; end Numbers.new.lazy.take(0).each_with_index.map { _1 }.to_a ``` Output (at ruby 3.2.7, and 3.3.0): ``` [0, 1, ..., 99] ``` Expected output (and was as at ruby 3.1.4): ``` [] ``` It works when it opposite ordering: `Numbers.new.lazy.each_with_index.take(0).map { _1 }.to_a`. I suspect it may be related to the change here https://github.com/ruby/ruby/pull/11868/files but I'm not familiar with any of that code. It seems like it replaces an allocated index with a counting index, which my hunch is it works for every value except for 0. -- https://bugs.ruby-lang.org/
7 8
0 0
[ruby-core:127301] [Ruby Bug#22496] Lazy enumerator `.each_with_index` no longer executes block
by rwstauner (Randy Stauner) 17 Nov '26

17 Nov '26
Issue #22496 has been reported by rwstauner (Randy Stauner). ---------------------------------------- Bug #22496: Lazy enumerator `.each_with_index` no longer executes block https://bugs.ruby-lang.org/issues/22496 * Author: rwstauner (Randy Stauner) * Status: Open * Backport: 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONTNEED ---------------------------------------- The fix for #21142 changed the behavior such that `lazy#each_with_index { ... }` is no longer running the block and just returning the enumerator. 4.0: ``` $ ruby -ve 'arr = []; p 3.times.lazy.each { |*a| arr << a }; p arr;' ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [x86_64-linux] 3 [[0], [1], [2]] $ ruby -ve 'arr = []; p 3.times.lazy.each_with_index { |*a| arr << a }; p arr;' ruby 4.0.7 (2026-09-15 revision 229531a6cf) +PRISM [x86_64-linux] 3 [[0, 0], [1, 1], [2, 2]] ``` 4.1.0dev: ``` $ ruby -ve 'arr = []; p 3.times.lazy.each { |*a| arr << a }; p arr;' ruby 4.1.0dev (2026-10-28T17:51:51Z master 5127bd0dbc) +PRISM [x86_64-linux] 3 [[0], [1], [2]] $ ruby -ve 'arr = []; p 3.times.lazy.each_with_index { |*a| arr << a }; p arr;' ruby 4.1.0dev (2026-10-28T17:51:51Z master 5127bd0dbc) +PRISM [x86_64-linux] #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 3:times>>:each_with_index(0)> [] ``` This seems inconsistent and likely unintentional. We must be missing tests for this case. -- https://bugs.ruby-lang.org/
3 2
0 0
[ruby-core:127455] [Ruby Bug#22542] ASCII-incompatible default_internal mislabels ENV and Dir strings without converting them
by jhawthorn (John Hawthorn) 17 Nov '26

17 Nov '26
Issue #22542 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #22542: ASCII-incompatible default_internal mislabels ENV and Dir strings without converting them https://bugs.ruby-lang.org/issues/22542 * Author: jhawthorn (John Hawthorn) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- `Encoding.default_internal` accepts ASCII-incompatible encodings like UTF-16LE. IO transcodes into it correctly, but ENV and Dir return the original UTF-8 bytes relabeled as UTF-16LE. ```shell $ LC_ALL=C.UTF-8 FOO=hello ruby -E UTF-8:UTF-16LE --disable-gems -e 'str = ENV["FOO"]; p str.bytes; p str.encoding; p str.valid_encoding?' [104, 101, 108, 108, 111] #<Encoding:UTF-16LE> false ``` The cause is the shortcut in `rb_external_str_new_with_enc` for ASCII-only input: ``` c /* ASCII compatible, and ASCII only string, no conversion in * default_internal */ if ((eidx == rb_ascii8bit_encindex()) || (eidx == rb_usascii_encindex()) || (rb_enc_asciicompat(eenc) && !search_nonascii(ptr, ptr + len))) { return rb_enc_str_new(ptr, len, ienc); } ``` This skips the conversion and tags the bytes with `ienc`, which is only valid if `ienc` is also ASCII-compatible. IO uses its own transcoding path, so it isn't affected. Related to #18338, which is the same kind of mislabeling caused by an ASCII-incompatible `default_external` (via the filesystem encoding). Should we even support non-ascii-compatible internal and external encodings? It doesn't seem like they've ever worked and so I can't imagine a demand for using them. -- https://bugs.ruby-lang.org/
2 1
0 0
  • ← Newer
  • 1
  • ...
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • ...
  • 19
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.