Skip to content

Commit 95cb7d6

Browse files
committed
Induce quoting of string scalars that start with 08 and 09
1 parent a86756a commit 95cb7d6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

test/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def test_yaml_1_2(self):
320320

321321
def test_yaml_1_1_octals(self):
322322
self.assertEqual(self.run_yq("on: -012345", ["-y", "."]), "'on': -5349\n")
323+
self.assertEqual(self.run_yq("on: '0900'", ["-y", "."]), "'on': '0900'\n")
323324

324325
@unittest.expectedFailure
325326
def test_yaml_1_2_octals(self):

yq/loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from yaml import SafeLoader as default_loader # type: ignore
2020

2121

22+
# Note the 1.1 resolver is modified from the default and only safe for use in dumping, not loading.
2223
core_resolvers = {
2324
"1.1": [
2425
{
@@ -45,9 +46,10 @@
4546
},
4647
{
4748
"tag": "tag:yaml.org,2002:int",
49+
# Line 2 of regexp modified to match all decimal digits, not just 0-7, to induce quoting of string scalars
4850
"regexp": re.compile(
4951
r"""^(?:[-+]?0b[0-1_]+
50-
|[-+]?0[0-7_]+
52+
|[-+]?0[0-9_]+
5153
|[-+]?(?:0|[1-9][0-9_]*)
5254
|[-+]?0x[0-9a-fA-F_]+
5355
|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$""",

0 commit comments

Comments
 (0)