https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-01-04T10:12:41ZRuby Issue Tracking SystemRuby master - Bug #5836: #slice results inconsistent after #force_encoding to a valid encodinghttps://bugs.ruby-lang.org/issues/5836?journal_id=230862012-01-04T10:12:41Zmanveru (Michael Fellinger)m.fellinger@gmail.com
<ul></ul><p>I've reduced the code a bit, calling <code>force_encoding</code> seems to cause it, and calling <code>valid_encoding?</code> repairs the damage.</p>
<p>s = 'abc'<br>
p [s.slice(3), s.slice(3, 1)]<br>
[nil, ""]</p>
<p>s.force_encoding 'euc-jp'<br>
p [s.slice(3), s.slice(3, 1)]<br>
[nil, nil]</p>
<p>s.valid_encoding?<br>
p [s.slice(3), s.slice(3, 1)]<br>
[nil, ""]</p>
<p>s.force_encoding 'euc-jp'<br>
p [s.slice(3), s.slice(3, 1)]<br>
[nil, nil]</p> Ruby master - Bug #5836: #slice results inconsistent after #force_encoding to a valid encodinghttps://bugs.ruby-lang.org/issues/5836?journal_id=230892012-01-04T14:24:42Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r34208.<br>
Brian, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>string.c (str_nth_len): count ascii-only run at the end. this<br>
bug appears only when single-byte-optimization is disabled due<br>
to unknown coderange. <a href="/issues/5836">[ruby-core:41896]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: #slice results inconsistent after #force_encoding to a valid encoding (Closed)" href="https://bugs.ruby-lang.org/issues/5836">#5836</a>]</li>
</ul>