Skip to content

Commit

Permalink
WAT: Do not try repairing invalid UTF-8 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Oct 3, 2024
1 parent ce5cba2 commit eb12092
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Sources/WAT/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ internal struct Parser {
return text
}
mutating func expectString() throws -> String {
String(decoding: try expectStringBytes(), as: UTF8.self)
// TODO: Use SE-0405 once we can upgrade minimum-supported Swift version to 6.0
let bytes = try expectStringBytes()
return try bytes.withUnsafeBufferPointer {
guard let value = String._tryFromUTF8($0) else {
throw WatParserError("invalid UTF-8 string", location: lexer.location())
}
return value
}
}

mutating func expectStringList() throws -> [UInt8] {
Expand Down
4 changes: 1 addition & 3 deletions Tests/WATTests/EncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ class EncoderTests: XCTestCase {
}

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

0 comments on commit eb12092

Please sign in to comment.