cmark-gfm-swift
cmark-gfm-swift copied to clipboard
Checkbox range is wrong if text has multibyte characters
This test will fail.
func testMarkdownCheckbox_withChecked_withMultibyte() {
let markdown = """
- [x] テスト
- [x] テスト2
"""
let node = Node(markdown: markdown)!
XCTAssertEqual(node.elements.count, 1)
guard case .list(let items, _)? = node.elements.first else { fatalError() }
// get second checkbox after multibyte characters
guard case .paragraph(let paragraph)? = items[1].first else { fatalError() }
guard case .checkbox(let checked, let range) = paragraph[1] else { fatalError() }
XCTAssertEqual(markdown.substring(with: range), "[x]")
}
The location of the checkbox should be converted into multibyte count here. I'm not sure the best way to get the whole content of the original markdown, but this might work.
var location = Int(cmark_node_get_checkbox_location(node))
if let string = String(bytes: original_markdown.utf8.prefix(location), encoding:.utf8) {
location = string.count
}
Yikes thanks for this. Sorry took me so long to get around to it. And thank you for the failing test. We will fix this.
Hi @rnystrom
It'd be appreciated if you will fix this! I think these bugs are also related to these.
https://github.com/GitHawkApp/GitHawk/issues/2753 https://github.com/GitHawkApp/GitHawk/issues/2655