Skip to content

Commit ae4c428

Browse files
authored
fix: Preview payload when correlating numeric properties (#671)
1 parent fdae74a commit ae4c428

File tree

1 file changed

+14
-1
lines changed
  • src/components/WebLogView/RequestDetails

1 file changed

+14
-1
lines changed

src/components/WebLogView/RequestDetails/utils.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export function parseParams(data: ProxyData) {
3535
return stringify(
3636
// TODO: https://github.com/grafana/k6-studio/issues/277
3737
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
38-
JSON.parse(jsonrepair(parsePythonByteString(contentDecoded)))
38+
JSON.parse(
39+
jsonrepair(
40+
parsePythonByteString(wrapTemplateExpressionsInQuotes(contentDecoded))
41+
)
42+
)
3943
)
4044
} catch (e) {
4145
console.error('Failed to parse query parameters', e)
@@ -64,3 +68,12 @@ export function isJsonString(str: string) {
6468
export function getRawContent(content: string) {
6569
return content.replace(/\s+/g, '')
6670
}
71+
72+
// When replacing number values in the payload, we need to wrap variable expressions
73+
// in quotes, otherwise JSON parse will fail
74+
function wrapTemplateExpressionsInQuotes(str: string) {
75+
return str.replace(
76+
/(:\s*)(\$\{[^}]+\})(?=[,}])/g,
77+
(_, prefix, expr) => `${prefix}"${expr}"`
78+
)
79+
}

0 commit comments

Comments
 (0)