Skip to content

Commit 031f5fe

Browse files
WAT: Do not try repairing invalid UTF-8 strings
1 parent 8315caf commit 031f5fe

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Sources/WAT/Parser.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ internal struct Parser {
154154
return text
155155
}
156156
mutating func expectString() throws -> String {
157-
String(decoding: try expectStringBytes(), as: UTF8.self)
157+
// TODO: Use SE-0405 once we can upgrade minimum-supported Swift version to 6.0
158+
let bytes = try expectStringBytes()
159+
return try bytes.withUnsafeBufferPointer {
160+
guard let value = String._tryFromUTF8($0) else {
161+
throw WatParserError("invalid UTF-8 string", location: lexer.location())
162+
}
163+
return value
164+
}
158165
}
159166

160167
mutating func expectStringList() throws -> [UInt8] {

Tests/WATTests/EncoderTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ class EncoderTests: XCTestCase {
106106
}
107107

108108
var stats = CompatibilityTestStats()
109-
let excluded: [String] = [
110-
"utf8-invalid-encoding.wast"
111-
]
109+
let excluded: [String] = []
112110
for wastFile in Spectest.wastFiles(include: [], exclude: excluded) {
113111
try TestSupport.withTemporaryDirectory { tempDir, shouldRetain in
114112
let jsonFileName = wastFile.deletingPathExtension().lastPathComponent + ".json"

0 commit comments

Comments
 (0)