Repository navigation
fix(designer): escape double quotes in string values of the key/value editor - #9749
Ming (MaxonT) wants to merge 2 commits into
Conversation
… editor Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
🔒 AI Validation PendingThis PR is from an external contributor. AI validation will be performed after manual review. Maintainers: Add the |
There was a problem hiding this comment.
🟡 Changes recommended
Escaping inferred strings for any-typed values leaves literal backslashes after collapse and expansion that persist when saved, requiring decoded-string handling and a regression test.
1 open issue
What changed in this PR
This PR addresses #7422 by escaping literal double quotes when the shared key/value editor builds collapsed JSON for string values, including JSON-formatted HTTP header text.
Changes:
- Escapes quotes in literal string segments while preserving existing token handling.
- Adds tests for JSON-string round trips and mixed literal/token values.
| File | Description |
|---|---|
libs/designer-ui/src/lib/editor/base/utils/keyvalueitem.ts |
Adds quote escaping for literal string values. |
libs/designer-ui/src/lib/editor/base/utils/__test__/keyvalueitem.spec.ts |
Tests valid JSON output and unchanged token quotes. |
Review effort: Balanced
| ? segment.value | ||
| : typeof segment.value === 'string' | ||
| ? escapeBackslash(segment.value) | ||
| ? escapeStringValue(segment.value, segment.type) |
There was a problem hiding this comment.
Good catch on the any path: expanding a collapsed say "hello" did leave the backslashes in. 03a2e8f makes serializecollapseddictionary.ts use the decoded string whenever JSON.parse returns a string, and serializecollapseddictionary.spec.ts now has the collapse → expand → collapse round trip with valueType: 'any'. That test fails without the change. The 11 dictionary tests pass here. I haven't run the full designer-ui suite or tried it in a browser. The red validate-pr check looks like it is only waiting for a maintainer to add the external-approved label.
…-typed dictionary Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
|
Hi there, would you be able to take a look? |

After reading the issue and the key/value editor code, I found the cause was small: double quotes in a string value weren't escaped when the collapsed JSON is built, and this escapes them.
The key/value (dictionary) editor builds a JSON object from the rows when it switches to the collapsed view. For a string-typed value it escaped backslashes and newlines but not double quotes, so a value such as
{"a":1,"b":"two"}was written as"X-Payload" : "{"a":1,"b":"two"}", which is not valid JSON and is what shows up as the parse error described in #7422.convertKeyValueItemToSegmentsnow also escapes"in literal segments of a string value, so the same text becomes"{\"a\":1,\"b\":\"two\"}".serializeDictionaryalready reads string values straight out ofJSON.parse, so the collapsed text maps back to the original value. Token segments are left as they were.Tests: two cases added to
keyvalueitem.spec.ts. One checks thatJSON.parseof the generated text returns the original JSON string as the header value; the other checks that literal quotes are escaped while a token value containing quotes is untouched. Both new cases fail without the change inkeyvalueitem.ts. The wholelibs/designer-uivitest run passes except 7 cases inpanelcontainer.spec.tsx, which fail the same way on the unchanged base.Not verified: I did not run the designer in a browser or the Portal, so I have not seen the header field itself accept JSON end to end. Only string-typed values are changed; the issue's suggestion of detecting JSON and stringifying it is covered by this for string values, and values of type
anyare untouched. Keys are not changed either.Refs #7422