forked from BigfootDev/flatbuffers
[ts] Builder incorrectly serializing empty strings (#7047)
* [ts] Builder incorrectly serializing empty strings The builder was returning an offset of zero for empty strings. This is leading to flatbuffers which fail verification in other languages, such as Rust. * tests expect 0 offset for null or undefined strings
This commit is contained in:
@@ -522,8 +522,11 @@ export class Builder {
|
|||||||
* @param s The string to encode
|
* @param s The string to encode
|
||||||
* @return The offset in the buffer where the encoded string starts
|
* @return The offset in the buffer where the encoded string starts
|
||||||
*/
|
*/
|
||||||
createString(s: string | Uint8Array): Offset {
|
createString(s: string | Uint8Array | null | undefined): Offset {
|
||||||
if (!s) { return 0 }
|
if (s === null || s === undefined) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let utf8: string | Uint8Array | number[];
|
let utf8: string | Uint8Array | number[];
|
||||||
if (s instanceof Uint8Array) {
|
if (s instanceof Uint8Array) {
|
||||||
utf8 = s;
|
utf8 = s;
|
||||||
|
|||||||
Reference in New Issue
Block a user