Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/SwiftSyntax/SyntaxParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ public enum SyntaxParser {
swiftparse_parser_set_diagnostic_handler(c_parser, diagHandler)
}

let c_top = swiftparse_parse_string(c_parser, source)
let c_top = source.withCString { buf in
swiftparse_parse_string(c_parser, buf, source.utf8.count)
}

// Get ownership back from the C parser.
// Get ownership back from the C parser.
return RawSyntax.moveFromOpaque(c_top)!
}
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/SwiftSyntaxTest/SyntaxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,10 @@ public class SyntaxTests: XCTestCase {
let sourceNsString = "var 🎉 = 2" as NSString
_ = try? SyntaxParser.parse(source: sourceNsString as String)
}

public func testParseFileWithNullCharacter() throws {
let source = "var x = 1\0\nvar y = 2"
let tree = try SyntaxParser.parse(source: source)
XCTAssertEqual(tree.description, source)
}
}