https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112022-11-07T12:51:33ZRuby Issue Tracking SystemRuby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=999772022-11-07T12:51:33Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><p>Possibly we should raise an exception if the string is not <code>ascii_only?</code></p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=999782022-11-07T14:17:55Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul></ul><p>I agree that at the very least the <code>unknown pack directive</code> warning should be made non-verbose (displayed even with <code>$VERBOSE=false</code>, and would make sense as <code>ArgumentError</code>.</p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1001912022-11-21T13:47:31ZEregon (Benoit Daloze)
<ul></ul><p>Agreed, I think it should be ArgumentError since it's otherwise silently ignoring characters in the pack format string.<br>
A non-verbose warning is better than the current state if ArgumentError is deemed too incompatible.</p>
<p>Here is real case where the silent warning caused confusion for <code>[1].pack('<L')</code>: <a href="https://github.com/oracle/truffleruby/issues/2791" class="external">https://github.com/oracle/truffleruby/issues/2791</a></p>
<p>EDIT: extracted to <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: pack/unpack silently ignores unknown directives (Closed)" href="https://bugs.ruby-lang.org/issues/19150">#19150</a></p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1002082022-11-22T08:26:58Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>chrisseaton (Chris Seaton) wrote in <a href="#note-1">#note-1</a>:</p>
<blockquote>
<p>Possibly we should raise an exception if the string is not <code>ascii_only?</code></p>
</blockquote>
<p>I think you want to mean "if the string is not ASCII-compatible".</p>
<p><a href="https://github.com/ruby/ruby/pull/6785" class="external">https://github.com/ruby/ruby/pull/6785</a></p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1002182022-11-22T17:23:21Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><blockquote>
<p>I think you want to mean "if the string is not ASCII-compatible".</p>
</blockquote>
<p>Can you explain why?</p>
<p>I think a string is only a valid pack format string if it is <code>ascii_only?</code> - if it isn't <code>ascii_only?</code> then there is a silent warning and the output encoding is changed. We're proposing raising an error up front if the string is not <code>ascii_only?</code>.</p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1002242022-11-23T02:57:04Zalanwu (Alan Wu)
<ul></ul><p>Checking <code>ascii_only?</code> would reject non-ascii comments which are fine:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">p</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">89</span><span class="p">].</span><span class="nf">pack</span><span class="p">(</span><span class="o"><<~</span><span class="no">PACK</span><span class="p">)</span><span class="sh">
C # 🚗
c
</span><span class="no">PACK</span>
<span class="nb">p</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">89</span><span class="p">].</span><span class="nf">pack</span><span class="p">(</span><span class="s1">'Cc'</span><span class="p">)</span>
<span class="c1"># Same output</span>
</code></pre> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1002602022-11-25T16:24:58ZEregon (Benoit Daloze)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/19150">Bug #19150</a>: pack/unpack silently ignores unknown directives</i> added</li></ul> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1003912022-12-01T08:15:02Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Template strings should be ASCII compatible, exceptions otherwise.</p>
<p>Matz.</p> Ruby master - Bug #19108: Format routines like pack blindly treat a string as ASCII-encodedhttps://bugs.ruby-lang.org/issues/19108?journal_id=1003942022-12-01T08:38:43Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="[Bug #19108] Check for the encoding of pack/unpack format" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/9869bd1d612b489df806cf95bcb56965a02424e0">git|9869bd1d612b489df806cf95bcb56965a02424e0</a>.</p>
<hr>
<p>[Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Format routines like pack blindly treat a string as ASCII-encoded (Closed)" href="https://bugs.ruby-lang.org/issues/19108">#19108</a>] Check for the encoding of pack/unpack format</p>