diff options
author | Naoya Yamashita <conao3@gmail.com> | 2023-10-25 22:22:21 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 06:22:21 -0700 |
commit | d4faa16d8d7a0183bd21522b66801094b8b52cc1 (patch) | |
tree | 8857c3557b08e1bf5259004068b963f880ce04d9 | |
parent | ee87412fa89add226d263ec7885193e07243aa4c (diff) |
Do not interpret characters that cannot be parsed in octal as int (#176)
ref:
https://yaml.org/type/int.html
https://yaml.org/type/float.html
-rwxr-xr-x | test/test.py | 1 | ||||
-rw-r--r-- | yq/loader.py | 24 |
2 files changed, 23 insertions, 2 deletions
diff --git a/test/test.py b/test/test.py index 861144b..ae5e390 100755 --- a/test/test.py +++ b/test/test.py @@ -317,6 +317,7 @@ class TestYq(unittest.TestCase): def test_yaml_1_1_octals(self): self.assertEqual(self.run_yq("on: -012345", ["-y", "."]), "'on': -5349\n") + self.assertEqual(self.run_yq("on: -012349", ["-y", "."]), "'on': -012349\n") @unittest.expectedFailure def test_yaml_1_2_octals(self): diff --git a/yq/loader.py b/yq/loader.py index 4ff6aa5..b20047b 100644 --- a/yq/loader.py +++ b/yq/loader.py @@ -87,13 +87,33 @@ core_resolvers = { }, { "tag": "tag:yaml.org,2002:int", - "regexp": re.compile(r"^(?:|0o[0-7]+|[-+]?(?:[0-9]+)|0x[0-9a-fA-F]+)$", re.X), + "regexp": re.compile( + r"""^(?: + # [-+]?0b[0-1_]+ # (base 2) + [-+]?0[0-7]+ # (base 8) + |[-+]?0o[0-7]+ # (base 8) + |[-+]?(0|[1-9][0-9]*) # (base 10) + # |[-+]?0[0-7_]+ # (base 8) + # |[-+]?0o[0-7_]+ # (base 8) + # |[-+]?(0|[1-9][0-9_]*) # (base 10) + # |[-+]?0x[0-9a-fA-F_]+ # (base 16) + # |[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+ # (base 60) + )$""", + re.X + ), "start_chars": list("-+0123456789"), }, { "tag": "tag:yaml.org,2002:float", "regexp": re.compile( - r"^(?:[-+]?(?:\.[0-9]+|[0-9]+(\.[0-9]*)?)(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$", # noqa + r"""^(?: + [-+]?([0-9][0-9]*)?\.[0-9.]*([eE][-+][0-9]+)? (base 10) + |[-+]?[0-9][0-9]*(:[0-5]?[0-9])+\.[0-9]* (base 60) + # |[-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)? (base 10) + # |[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]* (base 60) + |[-+]?\.(inf|Inf|INF) # (infinity) + |\.(nan|NaN|NAN) # (not a number) + )$""", re.X, ), "start_chars": list("-+0123456789."), |