summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Kislyuk <andrey.kislyuk@color.com>2024-04-17 15:12:08 -0700
committerAndrey Kislyuk <andrey.kislyuk@color.com>2024-04-17 15:12:08 -0700
commit95cb7d6b7d97c20b06d2d7a8d65fa35a6f495932 (patch)
tree34c6699a1649af00392317a6d70b1f384ac7f29a
parenta86756a31a3b2012efde89b856f00c73810392d7 (diff)
Induce quoting of string scalars that start with 08 and 09
-rwxr-xr-xtest/test.py1
-rw-r--r--yq/loader.py4
2 files changed, 4 insertions, 1 deletions
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 @@ 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: '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 @@ except ImportError:
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 @@ core_resolvers = {
},
{
"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])+)$""",