Skip to content

Commit

Permalink
Induce quoting of string scalars that start with 08 and 09
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Apr 17, 2024
1 parent a86756a commit 95cb7d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion yq/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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])+)$""",
Expand Down

0 comments on commit 95cb7d6

Please sign in to comment.