Skip to content

fix(grammar): support single-quoted keys in compound pairs - #64

Open
AnonymoDGH wants to merge 1 commit into
PrismarineJS:masterfrom
AnonymoDGH:fix/single-quoted-keys
Open

fix(grammar): support single-quoted keys in compound pairs#64
AnonymoDGH wants to merge 1 commit into
PrismarineJS:masterfrom
AnonymoDGH:fix/single-quoted-keys

Conversation

@AnonymoDGH

Copy link
Copy Markdown

Related to #63

Investigation of #63

The exact payload from the issue parses correctly on current master — single-quoted string values were already fixed by #53 (merged 2025-12-22). The reporter's stack trace (index.js:94, offset: 42, token: { value: 's' }) matches the published npm package 2.0.4 (2023-06-03), which predates that fix. I verified this by installing mojangson@2.0.4 and feeding it the issue's payload: it fails with the identical error, while master parses it fine.

So the main fix for #63 is already on master — it just hasn't been published (npm latest is still 2.0.4, master is 2.1.0). Publishing 2.1.0 would resolve the report.

What this PR fixes

While verifying, I found a genuine remaining gap: single-quoted keys still fail, even though Minecraft SNBT allows them:

mojangson.parse("{'key':'value'}")  // throws: offset 1, token "'"

The PAIR rule only accepted STRING as a key, and STRING's unquoted branch excludes '. This adds a SINGLE_QUOTED_STRING alternative to PAIR, so single-quoted keys work everywhere double-quoted keys do (including keys with spaces, colons, and escaped quotes).

Verified

  • {'key':'value'}, {'key':"value"}, {'a':1,"b":2}, {'my key':'v'}, {'minecraft:id':'x'}, nested {'outer':{'inner':'v'}} all parse correctly.
  • No regressions: unquoted keys, double-quoted keys, and single-quoted values all still work.
  • npm test: 140 passing (standard lint + mocha), including 6 new single-quoted-key cases.

Note: grammar.js is a gitignored build artifact regenerated from grammar.ne via nearleyc (prepublish), so only grammar.ne is changed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant