Skip to content

fix(designer): escape double quotes in string values of the key/value editor - #9749

Open
Ming (MaxonT) wants to merge 2 commits into
Azure:mainfrom
MaxonT:contrib/7422-auto
Open

Ming (MaxonT) wants to merge 2 commits into
Azure:mainfrom
MaxonT:contrib/7422-auto

Conversation

@MaxonT

Copy link
Copy Markdown

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. convertKeyValueItemToSegments now also escapes " in literal segments of a string value, so the same text becomes "{\"a\":1,\"b\":\"two\"}". serializeDictionary already reads string values straight out of JSON.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 that JSON.parse of 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 in keyvalueitem.ts. The whole libs/designer-ui vitest run passes except 7 cases in panelcontainer.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 any are untouched. Keys are not changed either.

Refs #7422

… editor

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 05:44
@github-actions

Copy link
Copy Markdown
Contributor

🔒 AI Validation Pending

This PR is from an external contributor. AI validation will be performed after manual review.

Maintainers: Add the external-approved label to enable AI validation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@MaxonT

Copy link
Copy Markdown
Author

Hi there, would you be able to take a look?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants