ReviewOS

also looking at this

craft-native/craft

fix(android): text going to the JVM is modified UTF-8, and was not being

#168
Merged chris wants to merge fix/android-modified-utf8 into main
12 files +326 -136
packages/zig/src/bridge_android_widgets.zigmodified+2-9
Changes to packages/zig/src/bridge_android_widgets.zig
@@ -137,7 +137,7 @@ pub fn writeUpdate(j: Jni, allocator: std.mem.Allocator, activity: jobject, upda
137137 defer _ = j.popLocalFrame(null);
138138 _ = try j.callObjectMethodA(editor, put_string, &.{
139139 .{ .l = try j.newStringUtf(field.key) },
140 .{ .l = try javaString(j, allocator, text) },
140 .{ .l = try j.newStringUtf8(allocator, text) },
141141 });
142142 }
143143 }
@@ -156,7 +156,7 @@ pub fn broadcast(j: Jni, allocator: std.mem.Allocator, activity: jobject, action
156156 const intent = try j.newObjectA(
157157 intent_cls,
158158 try j.methodId(intent_cls, "<init>", "(Ljava/lang/String;)V"),
159 &.{.{ .l = try javaString(j, allocator, action) }},
159 &.{.{ .l = try j.newStringUtf8(allocator, action) }},
160160 );
161161
162162 const activity_cls = try j.objectClass(activity);
@@ -181,13 +181,6 @@ pub fn broadcast(j: Jni, allocator: std.mem.Allocator, activity: jobject, action
181181 );
182182}
183183
184fn javaString(j: Jni, allocator: std.mem.Allocator, text: []const u8) !jni.jstring {
185 const terminated = try allocator.allocSentinel(u8, text.len, 0);
186 defer allocator.free(terminated);
187 @memcpy(terminated, text);
188 return j.newStringUtf(terminated.ptr);
189}
190
191184// =============================================================================
192185// Tests
193186// =============================================================================