Skip to content

Commit 46395a3

Browse files
committed
Merge branch 'codex/fix/datagrid-json-popover-full-value' into fix/datagrid
2 parents 3b87a5f + f6c9fff commit 46395a3

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

TablePro/Models/UI/JSONTreeNode.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,9 @@ internal enum JSONTreeParser {
108108
case .string(let raw):
109109
let decoded = JsonSyntaxParser.decodeStringLiteral(raw)
110110
let escaped = decoded.replacingOccurrences(of: "\"", with: "\\\"")
111-
let display: String
112-
let nsLen = (escaped as NSString).length
113-
if nsLen > 80 {
114-
display = "\"\((escaped as NSString).substring(to: 80))...\""
115-
} else {
116-
display = "\"\(escaped)\""
117-
}
118111
return JSONTreeNode(
119112
key: key, keyPath: keyPath, valueType: .string,
120-
displayValue: display, rawValue: decoded, children: []
113+
displayValue: "\"\(escaped)\"", rawValue: decoded, children: []
121114
)
122115

123116
case .number(let raw):
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// JSONTreeParserTests.swift
3+
// TableProTests
4+
//
5+
6+
import Foundation
7+
import Testing
8+
9+
@testable import TablePro
10+
11+
@Suite("JSONTreeParser")
12+
struct JSONTreeParserTests {
13+
@Test("Long string nodes keep the full display value")
14+
func longStringNodesKeepFullDisplayValue() {
15+
let longString = String(repeating: "abcdefghij", count: 12)
16+
let json = "{\"message\":\"\(longString)\"}"
17+
18+
let result = JSONTreeParser.parse(json)
19+
guard case .success(let root) = result else {
20+
Issue.record("Expected JSONTreeParser.parse to succeed")
21+
return
22+
}
23+
24+
guard let messageNode = root.children.first else {
25+
Issue.record("Expected a child node for message")
26+
return
27+
}
28+
29+
#expect(messageNode.valueType == .string)
30+
#expect(messageNode.rawValue == longString)
31+
#expect(messageNode.displayValue == "\"\(longString)\"")
32+
#expect(!messageNode.displayValue.contains("..."))
33+
}
34+
35+
@Test("Tree parser still rejects oversized documents")
36+
func oversizedDocumentStillRejected() {
37+
let oversizedValue = String(repeating: "a", count: 100_001)
38+
let json = "{\"message\":\"\(oversizedValue)\"}"
39+
40+
let result = JSONTreeParser.parse(json)
41+
guard case .failure(let error) = result else {
42+
Issue.record("Expected JSONTreeParser.parse to fail for oversized input")
43+
return
44+
}
45+
46+
switch error {
47+
case .tooLarge:
48+
break
49+
case .invalidJSON:
50+
Issue.record("Expected oversized input to hit the tooLarge guard first")
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)