From: "chrisseaton (Chris Seaton)" Date: 2022-11-07T12:51:33+00:00 Subject: [ruby-core:110639] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded Issue #19108 has been updated by chrisseaton (Chris Seaton). Possibly we should raise an exception if the string is not `ascii_only?` ---------------------------------------- Bug #19108: Format routines like pack blindly treat a string as ASCII-encoded https://bugs.ruby-lang.org/issues/19108#change-99977 * Author: chrisseaton (Chris Seaton) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- Format routines like pack and unpack blindly treat a string as ASCII-encoded, even if they aren't ASCII or ASCII-compatible. I tried to construct code that was misleading using ASCII-incompatible-encodings but couldn't do it in practice (no ASCII-incompatible encodings have a pack directive ASCII byte that is encoded as a printable character.) But I could demonstrate at least some strange behaviour: ``` p ['foo'].pack('u').encoding # => # p ['foo'].pack('u'.encode('UTF-32BE')).encoding # => # ``` This is because the NUL characters in the second one (which aren't really NUL characters - they're part of the directive characters) explicitly trigger the encoding to change to binary. There is a warning, but the warning is only for unexpected directives. How about disallowing or warning for non-ascii compatible format strings? -- https://bugs.ruby-lang.org/ Unsubscribe: