Skip to content

Commit 0422415

Browse files
authored
fix(core): handle complex value stringification in Property component (#10604)
Fixes #10535
1 parent df3a68c commit 0422415

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/core/components/property.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from "react"
22
import PropTypes from "prop-types"
3+
import { stringify } from "core/utils"
34

45
export const Property = ({ propKey, propVal, propClass }) => {
56
return (
67
<span className={ propClass }>
7-
<br />{ propKey }: { String(propVal) }</span>
8+
<br />{ propKey }: { stringify(propVal) }</span>
89
)
910
}
1011
Property.propTypes = {

test/unit/core/utils.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Map, fromJS } from "immutable"
1+
import { Map, fromJS, OrderedMap } from "immutable"
22
import {
33
mapToList,
44
parseSearch,
@@ -23,6 +23,7 @@ import {
2323
requiresValidationURL,
2424
extractFileNameFromContentDispositionHeader,
2525
deeplyStripKey,
26+
stringify,
2627
paramToIdentifier,
2728
paramToValue,
2829
generateCodeVerifier,
@@ -1310,6 +1311,37 @@ describe("utils", () => {
13101311
})
13111312
})
13121313

1314+
describe("stringify", () => {
1315+
it("returns the string as-is", () => {
1316+
expect(stringify("hello")).toBe("hello")
1317+
})
1318+
1319+
it("converts Immutable objects to plain JS and stringifies", () => {
1320+
const immutableMap = OrderedMap({ key: "value" })
1321+
expect(stringify(immutableMap)).toBe('{\n "key": "value"\n}')
1322+
})
1323+
1324+
it("stringifies plain JS objects", () => {
1325+
const obj = { key: "value" }
1326+
expect(stringify(obj)).toBe('{\n "key": "value"\n}')
1327+
})
1328+
1329+
it("returns empty string for null or undefined", () => {
1330+
expect(stringify(null)).toBe("")
1331+
expect(stringify(undefined)).toBe("")
1332+
})
1333+
1334+
it("calls toString for numbers", () => {
1335+
expect(stringify(42)).toBe("42")
1336+
})
1337+
1338+
it("falls back to String() on JSON.stringify error", () => {
1339+
const circularObj = {}
1340+
circularObj.self = circularObj
1341+
expect(stringify(circularObj)).toBe("[object Object]")
1342+
})
1343+
})
1344+
13131345
describe("parse and serialize search", () => {
13141346
beforeEach(() => {
13151347
// jsdom in Jest 25+ prevents modifying window.location,

0 commit comments

Comments
 (0)