RangeError: premature EOF for Unicode character U+FEFF on start
See original GitHub issueHello,
We’ve noticed that whenever the Unicode ZWNBSP character(U+FEFF) is received on start of the string of a message, it throws a silent error and omits the character in the decoded part. It seems that, this particular execution of TextDecoder.decode throws the mentioned error:
I’ve created a repository to reproduce:
https://github.com/kivancguckiran/premature-eof-protobuf-ts
Outputted the charcodes from the result of the create
operation and after fromBinary
operation. If the U+FEFF character is in the start, it is ommited from decoded part.
Since it is Zero-Width-No-Break-Space, github preview hides the mentioned unicode character.
This line is: https://github.com/kivancguckiran/premature-eof-protobuf-ts/blob/main/index.ts#L4
Actually like this:
Thanks in advance.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Released in v2.8.0.
I can’t seem to find any information about whether or not the BOM should be ignored or not in protobuf strings. They’re definitely ignored when
protoc
is reading a proto file to compile, but as far as the actual runtimes go I see no tests regarding the BOM in string field values.I think the correct thing would be to update protobuf-ts to use the
ignoreBOM
setting, but I can’t be certain without seeing an existing test or docs. For an immediate workaround what you have is basically what I would’ve recommended, but you should only need to create theTextDecoder
instance once.I wouldn’t recommend the following approach, but you can monkey-patch the
BinaryReader
prototype so that you can avoid needing to import and pass the options everywhere. Just note that you will need to execute (import) this code once before callingfromBinary()
to be effective.