diff --git a/test/test.py b/test/test.py index d54a351..9cb570f 100755 --- a/test/test.py +++ b/test/test.py @@ -320,6 +320,7 @@ def test_yaml_1_2(self): def test_yaml_1_1_octals(self): self.assertEqual(self.run_yq("on: -012345", ["-y", "."]), "'on': -5349\n") + self.assertEqual(self.run_yq("on: '0900'", ["-y", "."]), "'on': '0900'\n") @unittest.expectedFailure def test_yaml_1_2_octals(self): diff --git a/yq/loader.py b/yq/loader.py index 4ff6aa5..e477814 100644 --- a/yq/loader.py +++ b/yq/loader.py @@ -19,6 +19,7 @@ from yaml import SafeLoader as default_loader # type: ignore +# Note the 1.1 resolver is modified from the default and only safe for use in dumping, not loading. core_resolvers = { "1.1": [ { @@ -45,9 +46,10 @@ }, { "tag": "tag:yaml.org,2002:int", + # Line 2 of regexp modified to match all decimal digits, not just 0-7, to induce quoting of string scalars "regexp": re.compile( r"""^(?:[-+]?0b[0-1_]+ - |[-+]?0[0-7_]+ + |[-+]?0[0-9_]+ |[-+]?(?:0|[1-9][0-9_]*) |[-+]?0x[0-9a-fA-F_]+ |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$""",