Skip to content

Commit

Permalink
Fix inconsistent interpolation with empty mappings and tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSignPainter98 committed Nov 20, 2023
1 parent 556fd59 commit 44d276b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions starlark/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,8 +1659,10 @@ func interpolate(format string, x Value) (Value, error) {
index++
}

if index < nargs {
return nil, fmt.Errorf("too many arguments for format string")
if _, ok := x.(Mapping); !ok {
if index < nargs {
return nil, fmt.Errorf("too many arguments for format string")
}
}

return String(buf.String()), nil
Expand Down
2 changes: 2 additions & 0 deletions starlark/testdata/string.star
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ assert.eq(gothash, wanthash)
# TODO(adonovan): ordered comparisons

# string % tuple formatting
assert.eq("A" % (), "A")
assert.eq("A %d %x Z" % (123, 456), "A 123 1c8 Z")
assert.eq("A" % {'unused': 123}, "A")
assert.eq("A %(foo)d %(bar)s Z" % {"foo": 123, "bar": "hi"}, "A 123 hi Z")
assert.eq("%s %r" % ("hi", "hi"), 'hi "hi"') # TODO(adonovan): use ''-quotation
assert.eq("%%d %d" % 1, "%d 1")
Expand Down

0 comments on commit 44d276b

Please sign in to comment.