Fix keyvalueOptions to process braces and backslahses better #1031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes several issues with the
keyvalueOptions()
utility's handling of braces and control sequences, and adds an extra parameter that controls whether it should do LaTeX3-style processing, or traditional processing.The current implementation doesn't handle some control sequences properly, in particular,
\{
, so,with throw an error about a missing closing brace or extra open brace. This PR fixes that issue with the addition of
case '\\'
in thereadValue()
function.The current implementation doesn't always handle braces properly. For example
returns
{ a: "x}" }
rather than{ a: "{x}y"}
. This is due to thinking that there are two outer sets of braces to be removed, rather than only one (start
isn't decremented where it should be, so theif (start > brace) { start = brace }
is moved to a location that takes care of that.Finally, the current implementation doesn't remove an outer set of braces for the entire string, as it should. That is,
returns
{ "x = y": true }
rather than{ x: "y" }
, as expected. This is corrected via thedropBraces
flag that allows one level of bracing to be removed.In addition to these changes, we add a flag to
keyvalueOptions()
that determines whether the LaTeX3 rules are to be used, or the traditional LaTeX2 rules, for parsing the key-value pairs. The difference is that traditional parsing removes any number of outermost braces, while LaTeX3 only removes one. Sowould return
{ x: "y" }
using traditional rules, whilewould return
{ x: "{y}" }
using LaTeX3 rules (the finaltrue
parameter controls this).LaTeX3 key-value parsing has the ability to check types of arguments and report errors, but that has not been implemented here. It might be worth doing so in the future.