diff --git a/build.sc b/build.sc index 73613bb0d..b6aaa0427 100644 --- a/build.sc +++ b/build.sc @@ -1,5 +1,5 @@ import mill._, scalalib._, publish._, scalajslib._, scalanativelib._, scalanativelib.api._ -val sjsonnetVersion = "0.4.5" +val sjsonnetVersion = "0.4.7" object sjsonnet extends Cross[SjsonnetModule]("2.12.13", "2.13.4") class SjsonnetModule(val crossScalaVersion: String) extends Module { diff --git a/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala b/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala index 9631424fd..a2829fa2a 100644 --- a/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala +++ b/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala @@ -442,9 +442,9 @@ object PrettyYamlRenderer{ (digits.? ~ "." ~ digits | digits ~ ".") ~ (("e" | "E") ~ ("+" | "-").? ~ digits).? ) def yamlOctalSuffix[_: P] = P( "x" ~ CharIn("1-9a-fA-F") ~ CharsWhileIn("0-9a-fA-F").? ) - def yamlHexSuffix[_: P] = P( "o".? ~ CharIn("1-7") ~ CharsWhileIn("0-7").? ) + def yamlHexSuffix[_: P] = P( "o" ~ CharIn("1-7") ~ CharsWhileIn("0-7").? ) def yamlOctalHex[_: P] = P( "0" ~ (yamlOctalSuffix | yamlHexSuffix) ) - def yamlNumber0[_: P] = P( ".inf" | yamlFloat | yamlOctalHex | CharIn("1-9") ~ digits.? | "0" ) + def yamlNumber0[_: P] = P( ".inf" | yamlFloat | yamlOctalHex | digits ) // Add a `CharIn` lookahead to bail out quickly if something cannot possibly be a number def yamlNumber[_: P] = P( "-".? ~ yamlNumber0 ) diff --git a/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.jsonnet b/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.jsonnet new file mode 100644 index 000000000..15105e3a6 --- /dev/null +++ b/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.jsonnet @@ -0,0 +1,15 @@ +{ +accountId1: "088579281390", +accountId2: "788579281397", +accountId3: "022216176144", +accountId4: "111216176140", +accountId5: "01111110", +accountId6: '011111111110', +accountId7: "011111111110", +accountId8: '081111111190', +accountId9: '081111111110', +accountIdA: '081111111111', +accountIdB: '011111111111', +accountIdC: '089999999999' + +} \ No newline at end of file diff --git a/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.yaml b/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.yaml new file mode 100644 index 000000000..70fc0175f --- /dev/null +++ b/sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.yaml @@ -0,0 +1,12 @@ +accountId1: '088579281390' +accountId2: '788579281397' +accountId3: '022216176144' +accountId4: '111216176140' +accountId5: '01111110' +accountId6: '011111111110' +accountId7: '011111111110' +accountId8: '081111111190' +accountId9: '081111111110' +accountIdA: '081111111111' +accountIdB: '011111111111' +accountIdC: '089999999999' \ No newline at end of file diff --git a/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala b/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala index 1ee0a9e4e..7d3e9e196 100644 --- a/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala +++ b/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala @@ -34,6 +34,12 @@ object PrettyYamlRendererTests extends TestSuite{ eval(nontrivial / "mixins.jsonnet", comments = true) ==> os.read(nontrivial / "mixins.golden.comments.yaml") } + test("nounquoted"){ + // Ensure weird octal-number-like strings are quoted, to avoid + // edge cases that may cause problems for non-compliant parsers + eval(nontrivial / "quotingNumberLikeStrings.jsonnet", comments = false) ==> + os.read(nontrivial / "quotingNumberLikeStrings.yaml") + } } }