Skip to content

Commit 01eebe6

Browse files
committed
Fixes #1986. String#slice on multibyte chars raise Exception
1 parent 87bf291 commit 01eebe6

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

core/src/main/java/org/jruby/util/StringSupport.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,24 +357,12 @@ public static int preciseCodePoint(Encoding enc, byte[]bytes, int p, int end) {
357357
}
358358

359359
@SuppressWarnings("deprecation")
360-
public static int utf8Nth(byte[]bytes, int p, int end, int n) {
361-
if (UNSAFE != null) {
362-
if (n > LONG_SIZE * 2) {
363-
int ep = ~LOWBITS & (p + LOWBITS);
364-
while (p < ep) {
365-
if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) n--;
366-
}
367-
Unsafe us = (Unsafe)UNSAFE;
368-
int eend = ~LOWBITS & end;
369-
do {
370-
n -= countUtf8LeadBytes(us.getLong(bytes, (long)(OFFSET + p)));
371-
p += LONG_SIZE;
372-
} while (p < eend && n >= LONG_SIZE);
373-
}
374-
}
375-
while (p < end) {
360+
public static int utf8Nth(byte[]bytes, int p, int e, int nth) {
361+
// FIXME: Missing our UNSAFE impl because it was doing the wrong thing: See GH #1986
362+
while (p < e) {
376363
if ((bytes[p] & 0xc0 /*utf8 lead byte*/) != 0x80) {
377-
if (n-- == 0) break;
364+
if (nth == 0) break;
365+
nth--;
378366
}
379367
p++;
380368
}

0 commit comments

Comments
 (0)