From 27d4277b6eb3c4c0f13e0bc991c50c10272f460d Mon Sep 17 00:00:00 2001 From: Stephanie DiBenedetto Date: Mon, 17 Jun 2024 10:46:27 -0700 Subject: [PATCH] clarify enforceUtf8 argument Co-authored-by: Luke Sandberg --- binary/decoder_test.js | 8 ++++---- generator/js_generator.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/binary/decoder_test.js b/binary/decoder_test.js index b8e1084..7a71c0d 100644 --- a/binary/decoder_test.js +++ b/binary/decoder_test.js @@ -375,11 +375,11 @@ describe('binaryDecoderTest', () => { const decoder = jspb.BinaryDecoder.alloc(encoder.end()); - expect(decoder.readString(ascii.length, true)).toEqual(ascii); - expect(utf8_two_bytes).toEqual(decoder.readString(2, true)); + expect(decoder.readString(ascii.length, /* enforceUtf8= */ true)).toEqual(ascii); + expect(utf8_two_bytes).toEqual(decoder.readString(2, /* enforceUtf8= */ true)); expect(utf8_three_bytes) - .toEqual(decoder.readString(3, true)); - expect(utf8_four_bytes).toEqual(decoder.readString(4, true)); + .toEqual(decoder.readString(3, /* enforceUtf8= */ true)); + expect(utf8_four_bytes).toEqual(decoder.readString(4, /* enforceUtf8= */ true)); }); /** diff --git a/generator/js_generator.cc b/generator/js_generator.cc index 8136f58..6ca0ad3 100644 --- a/generator/js_generator.cc +++ b/generator/js_generator.cc @@ -1079,7 +1079,7 @@ std::string JSBinaryMethodType(const FieldDescriptor* field, bool is_writer) { name[0] = (name[0] - 'a') + 'A'; } if (!is_writer && field->type() == FieldDescriptor::TYPE_STRING && - field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { + field->requires_utf8_validation()) { name = name + "RequireUtf8"; } return IsIntegralFieldWithStringJSType(field) ? (name + "String") : name;