From d103b623d7fae40784aac12798244a29f13b3eba Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Tue, 26 Nov 2024 12:00:48 -0800 Subject: [PATCH] Add missing reserved words to check in dump/dumps. When deciding whether to encode a key as an identifier instead of a string, the encoding logic checks against a list of reserved words to avoid conflicts. The existing code is based on the list in section 7.6.1 of EcmaScript 5.1. However, it turns out that I was missing some of the future reserved words: - implements - interface - let - package - private - protected - public - static - yield. This CL adds them to the list. This fixes GitHub #87. Note that this will introduce some backwards incompatibility (because now those words will be quoted when encoded), but I think that's probably better to do than to leave the bug open. If this causes problems, we can revert this list and either add an option to check for them or just wait until we can do a non-backwards-compatible release. --- json5/lib.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/json5/lib.py b/json5/lib.py index d5c1a94..c4c638a 100644 --- a/json5/lib.py +++ b/json5/lib.py @@ -818,12 +818,20 @@ def is_reserved_word(self, key: str) -> bool: 'for', 'function', 'if', + 'implements', 'import', 'in', 'instanceof', + 'interface', + 'let', 'new', 'null', + 'package', + 'private', + 'protected', + 'public', 'return', + 'static', 'super', 'switch', 'this', @@ -835,6 +843,7 @@ def is_reserved_word(self, key: str) -> bool: 'void', 'while', 'with', + 'yield', ] ) + ')$'