Skip to content

Commit b2f21bb

Browse files
committed
Update DebuggerSupport.swift
1 parent 180a11f commit b2f21bb

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

stdlib/public/core/DebuggerSupport.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ public enum _DebuggerSupport {
148148
return count == 1 ? "1 element" : "\(count) elements"
149149
case .`struct`?, .`enum`?, nil:
150150
switch value {
151-
case let x as String:
152-
return x.description
153151
case let x as CustomDebugStringConvertible:
154152
return x.debugDescription
155153
case let x as CustomStringConvertible:
@@ -240,7 +238,13 @@ public enum _DebuggerSupport {
240238
print("\(name) : ", terminator: "", to: &target)
241239
}
242240

243-
if let str = asStringRepresentation(value: value, mirror: mirror, count: count) {
241+
if isRoot, let value = value as? String {
242+
// We don't want to use string's debug desciprtion for 'po' because it
243+
// escapes the string and prints it raw (e.g. prints "\n" instead of
244+
// actually printing a newline), but only if its the root value. Otherwise,
245+
// continue using the debug description.
246+
print(value, terminator: "", to: &target)
247+
} else if let str = asStringRepresentation(value: value, mirror: mirror, count: count) {
244248
print(str, terminator: "", to: &target)
245249
}
246250

test/stdlib/BridgedObjectDebuggerSupport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ StringForPrintObjectTests.test("NSStringUTF8") {
7777
let debug = debugVal(&newNSUTF16)
7878
expectEqual("🏂☃❅❆❄︎⛄️❄️", String(reflecting: nsUTF16))
7979
expectEqual("\"🏂☃❅❆❄︎⛄️❄️\"", String(reflecting: newNSUTF16))
80-
expectEqual("\"🏂☃❅❆❄︎⛄️❄️\"\n", printed)
80+
expectEqual("🏂☃❅❆❄︎⛄️❄️\n", printed)
8181
expectEqual(printed, debug)
8282
}
8383

test/stdlib/DebuggerSupport.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ StringForPrintObjectTests.test("DontBridgeThisStruct") {
101101
}
102102
#endif
103103

104+
if #available(SwiftStdlib 6.0, *) {
105+
StringForPrintObjectTests.test("String") {
106+
let printed = _stringForPrintObject("hello\nworld")
107+
expectEqual(printed, "hello\nworld\n")
108+
}
109+
}
110+
104111
class RefCountedObj {
105112
var patatino : Int
106113
init(_ p : Int) {

0 commit comments

Comments
 (0)