KantConnect opened a new pull request, #3475:
URL: https://github.com/apache/thrift/pull/3475
A Thrift set is defined to contain unique elements, but currently different
language implementations have handled duplicate elements inconsistently: Go
throws, Python silently deduplicates, while Node.js passed duplicates through
unchanged, breaking cross-language interop.
Add duplicate-element validation in the JavaScript code generator and
runtime libraries:
* lib/nodejs/lib/thrift/thrift.js, lib/js/src/thrift.js: new
Thrift.checkSetUniqueness(arr) helper. Duplicate detection via a native JS Set;
throws TProtocolException(INVALID_DATA) on the first duplicate. Both the
Node.js and the browser/ES6/TS runtime libraries are updated, since the JS code
generator emits the same Thrift.checkSetUniqueness call regardless of target.
* compiler/cpp/src/thrift/generate/t_js_generator.cc: in
generate_serialize_container() emit a Thrift.checkSetUniqueness call
immediately before output.writeSetBegin(), so the validation runs before any
bytes hit the transport. In generate_deserialize_container() for sets, allocate
one parallel `new Set()` before the per-element loop; in
generate_deserialize_set_element() guard the push with seen.has(elem) /
seen.add(elem).
* lib/nodejs/test/check_set_uniqueness.test.js,
lib/nodejs/test/testAll.sh: new tape unit tests covering unique sets, duplicate
sets across primitive types, empty/single-element edge cases, and the thrown
exception type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]