fix(web-core): JSON-stringify objects/arrays in formatString per spec#1430
fix(web-core): JSON-stringify objects/arrays in formatString per spec#1430BBC6BAE9 wants to merge 5 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the formatString function to align with the A2UI protocol by JSON-stringifying objects and arrays and converting null/undefined values to empty strings. A potential issue was identified where JSON.stringify could cause the UI to crash if it encounters circular references or BigInt values; a more robust implementation with error handling and a fallback was suggested.
b749dcc to
befef6b
Compare
FormatStringImplementation used Array.prototype.join('') which relied on
JS default String(value) coercion, producing '[object Object]' for objects
and flattened comma-separated values for arrays. The a2ui_protocol.md
§"Type conversion" requires objects/arrays to be stringified as JSON.
Fixes google#1386
befef6b to
800e435
Compare
Wrap JSON.stringify in try-catch to handle circular references and BigInt values gracefully, falling back to String(value) on failure. Also use nullish coalescing to guard against toJSON returning undefined.
800e435 to
0031462
Compare
Description
FormatStringImplementationusedArray.prototype.join('')which relied on JS defaultString(value)coercion, producing[object Object]for objects and flattened comma-separated values for arrays. Thea2ui_protocol.md§"Type conversion" requires objects/arrays to be stringified as JSON.Changes:
coerceToStringhelper that implements the spec's type conversion rules:null/undefined→"", objects/arrays →JSON.stringify(), scalars →String()FormatStringImplementationto usecoerceToStringReproduction (from issue):
web_corebefore fix"Tags: ${/tags}"Tags: ["swift","ios"]Tags: swift,ios"User: ${/user}"User: {"name":"Alice","age":30}User: [object Object]"M = ${/matrix}"M = [[1,2],[3,4]]M = 1,2,3,4"V = ${/vals}"V = [1,null,3]V = 1,,3Fixes #1386
Pre-launch Checklist
If you need help, consider asking for advice on the discussion board.