Skip to content
Open
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
9 changes: 9 additions & 0 deletions sjsonnet/src/sjsonnet/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,15 @@ object Format {
Error.fail(
"expected number at position %d, got string".format(i)
)
if (formatted.conversion == 'c') {
val s = vs.str
val cpCount = s.codePointCount(0, s.length)
if (cpCount != 1)
Error.fail(
"%%c expected 1-sized string got: %d".format(cpCount),
pos
)
}
widenRaw(formatted, vs.str)
case vn: Val.Num =>
val s = vn.asDouble
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%c" % "AB"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] %c expected 1-sized string got: 2
at [<root>].(error.format_c_multi_char_string.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Regression tests for std.format %c — verified against C++ jsonnet v0.21.0
// Success cases: single-char strings and numeric codepoints
std.assertEqual("%c" % "A", "A") &&
std.assertEqual("%c" % 65, "A") &&
std.assertEqual("%c" % "世", "世") &&
std.assertEqual("%c" % 127757, "🌍") &&
std.assertEqual("%10c" % "A", " A") &&
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Loading