* allow for an optional semicolon where there is an optional comma in parseOptionValue
* set allowShortCircuit to true to prevent no-unused-expressions error
* add test for semicolon
Co-authored-by: Alexander Fenster <fenster@google.com>
* deps: set @types/node to star version
When using `protobuf.js` as a dependency in a project it is important
that `@types/node` package gets de-duped and has the same version as for
the rest of the modules in the project. Otherwise, typing conflicts
could happen as they do between v13 and v14 node types.
* fix: use @types/node >=13.7.0
* fix: use @types/node >=13.7.0
Co-authored-by: Alexander Fenster <fenster@google.com>
Co-authored-by: Alexander Fenster <github@fenster.name>
* fix utf8 -> utf16 decoding bug on surrogate pairs
This fixes https://github.com/protobufjs/protobuf.js/issues/1473
The custom utf8 -> utf16 decoder appears to be subtly flawed. From my reading it appears the chunking mechanism doesn't account for surrogate pairs at the end of a chunk causing variable size chunks. A larger chunk followed by a smaller chunk leaves behind garbage that'll be included in the latter chunk.
It looks like the chunking mechanism was added to prevent stack overflows when calling `formCharCode` with too many args. From some benchmarking it appears putting utf16 code units in an array and spreading that into `fromCharCode` wasn't helping performance much anyway. I simplified it significantly.
Here's a repro of the existing encoding bug in a fuzzing suite
https://repl.it/@turbio/oh-no-our-strings#decoder.js
* fix lint
* add test case for surrogate pair bug
Co-authored-by: Alexander Fenster <fenster@google.com>
* Rebuild gentest sources
* Incorporate gentests into make
Also reorder tasks so type linting is done against newly generated code vs. old.
* fix: add newline to package.json
Co-authored-by: Alexander Fenster <fenster@google.com>
Co-authored-by: Alexander Fenster <github@fenster.name>
According to [1], map encoding must be compatible with a repeated message
using indices 1 and 2 for key and value. In particular this implies that
both key and value may be omitted when they are equal to the default
value - which some protobuf implementations like protobuf-c actually do.
The comments in the added testcase are based on the output of
protobuf-inspector [2].
[1] https://developers.google.com/protocol-buffers/docs/proto3#backwards-compatibility
[2] https://github.com/jmendeth/protobuf-inspector
Based-on-patch-by: Shrimpz <Shrimpz@qq.com>
Co-authored-by: Alexander Fenster <fenster@google.com>
* Add option parsing tests to ensure no regressions are caused
* Properly parse option values into objects in addition to the regular option parsing. Repeated options are preserved as well as repeated fields within nested options.
Parsed options are kept in a parsedOptions field on every level (message, field etc.)
* fix: bad merge
* fix: lint
* fix: lint
* fix: lint
* fix: lint
* fix: lint
* fix: build types
Co-authored-by: Alexander Fenster <fenster@google.com>
Co-authored-by: Alexander Fenster <github@fenster.name>
* fix trailing comment in last line recognized as leading comment for current token.
* add preferTrailingComment to IParseOptions
Co-authored-by: Alexander Fenster <fenster@google.com>