Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox range is wrong if text has multibyte characters #11

Open
daisukes opened this issue Mar 13, 2019 · 2 comments
Open

Checkbox range is wrong if text has multibyte characters #11

daisukes opened this issue Mar 13, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@daisukes
Copy link

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
        }
@rnystrom rnystrom added the bug Something isn't working label Jun 3, 2019
@rnystrom
Copy link
Member

rnystrom commented Jun 3, 2019

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.

@daisukes
Copy link
Author

daisukes commented Nov 9, 2019

Hi @rnystrom

It'd be appreciated if you will fix this! I think these bugs are also related to these.

GitHawkApp/GitHawk#2753
GitHawkApp/GitHawk#2655

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants