It was an oversight to make them encode codepoints; they were always intended to
be equivalent to their Go counterparts, which encode bytes and can be used to
write arbitrary byte sequences that are not necessarily valid UTF-8 sequences.
With the previous fix, the parsing algorithm could still backtrack without
making progress given slightly more sophisticated input (see added testdata for
an example).
Instead of trying to parse a temporary assignment when it *could* be one, only
parse it when we are sure that it is. This should now truly fix the issue.
The parsing function for Form first tries to parse a temp assignment, and
backtracks when an assignment cannot be parsed. When the input is "(" repeated n
times, each level of Form parsing will first try to parse the rest of the code
as an assignment and then backtrack, without making any progress. This results
in a call tree with a branching factor of 2, hence the O(2^n) complexity.
The fix is to first try to parse a head instead, and only try to parse it as a
temp assignment if it does contain "=". This fixes this particular pathological
case, although I'm not 100% sure it eliminates all possibilities of O(2^n) time
complexity.
With the introduction of the "tmp" special command, the current syntax for
temporary assignments will be deprecated and eventually go away, which will
eliminate all backtracking in the parser. In the meanwhile, this fix may be good
enough.
This case was discovered with fuzzing support in Go 1.18. Also add the fuzzing
test data.
Only depend on the tools referenced by tools/md-to-html. This uses "grep -o",
which is not part of POSIX but is supported by both GNU and BSD greps, so widely
enough.
Also remove support for the "name" field tag from eval.scanOptions - it's not
used anywhere and the use case it was intended for is handled by CamelToDashed.
- Don't require creating a Getopt object in the API.
- Add a new Parse function, and rename the existing method to Complete.
- Add an Unknown field to Option to indicate unknown options.
- Rewrite the tests.
- Numerous stylistic changes.