Skip to content

Commit 928a557

Browse files
committed
isScalar needs to reject invalid ASCII
0x80 - 0xFF are invalid ascii, and thus, need to not return true always.
1 parent 13ef2a0 commit 928a557

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

stdlib/public/core/ASCII.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Unicode.ASCII: Unicode.Encoding {
3030
@inline(__always)
3131
@inlinable
3232
public static func _isScalar(_ x: CodeUnit) -> Bool {
33-
return true
33+
return isASCII(x)
3434
}
3535

3636
@inline(__always)

test/stdlib/Unicode.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,12 @@ UnicodeAPIs.test("UTF-8 and UTF-16 queries") {
110110
}
111111
}
112112

113+
114+
UnicodeAPIs.test("ASCII._isScalar") {
115+
expectTrue(ASCII._isScalar(0))
116+
expectTrue(ASCII._isScalar(0x7F))
117+
expectFalse(ASCII._isScalar(0x80))
118+
expectFalse(ASCII._isScalar(0xFF))
119+
}
120+
113121
runAllTests()

0 commit comments

Comments
 (0)