Files
swift-mirror/test/stdlib/PrintString.swift
Karoy Lorentey 1241df3fab [stdlib] String.debugDescription: Fix quoting behavior
`String.debugDescription` currently fails to protect the contents of
the string from combining with the opening or closing `”` characters
or one of the characters of a quoted scalar:

```swift
let s = “\u{301}A\n\u{302}B\u{70F}”
print(s.debugDescription)
// ⟹ “́A\n̂B܏”  (characters: “́, A, \, n̂, B, ܏”)
```

This can make debug output difficult to read, as string contents are
allowed to spread over and pollute neighboring meta-characters.

This change fixes this by force-quoting the problematic scalars in
these cases:

```swift
let s = “\u{301}A\n\u{302}B\u{70F}”
print(s.debugDescription)
// ⟹ “\u{301}A\n\u{302}B\u{70F}”
```

Of course, Unicode scalars that don’t engage in such behavior are
still allowed to pass through unchanged:

```swift
let s = “Cafe\u{301}”
print(s.debugDescription)
// ⟹ “Café”
```
2023-01-16 01:15:39 -08:00

5.7 KiB