Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid generating unquoted octal-like strings to avoid parser bugs #183

Merged
merged 12 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

}
12 changes: 12 additions & 0 deletions sjsonnet/test/resources/nontrivial/quotingNumberLikeStrings.yaml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Loading