Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 715311fa authored by Jeff Brown's avatar Jeff Brown
Browse files

Fix regression in CursorWindow.getString()

Bug: 5332296

NewStringUTF expects modified UTF-8, so it barfs on UTF-8 strings
that contain high codepoints.  Even though it results in an extra
copy being performed, first convert to UTF-16, then call NewString.

Change-Id: Idbfeb3cc2c4b731834e4482848dcac2fa33ec2d0
parent 7ce74524
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -205,8 +205,14 @@ static jstring nativeGetString(JNIEnv* env, jclass clazz, jint windowPtr,
    if (type == FIELD_TYPE_STRING) {
        uint32_t size = fieldSlot->data.buffer.size;
#if WINDOW_STORAGE_UTF8
        return size > 1 ? env->NewStringUTF(window->getFieldSlotValueString(fieldSlot))
                : gEmptyString;
        if (size <= 1) {
            return gEmptyString;
        }
        // Convert to UTF-16 here instead of calling NewStringUTF.  NewStringUTF
        // doesn't like UTF-8 strings with high codepoints.  It actually expects
        // Modified UTF-8 with encoded surrogate pairs.
        String16 utf16(window->getFieldSlotValueString(fieldSlot), size - 1);
        return env->NewString(reinterpret_cast<const jchar*>(utf16.string()), utf16.size());
#else
        size_t chars = size / sizeof(char16_t);
        return chars ? env->NewString(reinterpret_cast<jchar*>(