johnxnguyen / Down

Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.
Other
2.22k stars 313 forks source link

Update to cmark 0.30.2 #278

Open apps4everyone opened 2 years ago

apps4everyone commented 2 years ago

Update to cmark 0.30.2

Parth commented 2 years ago

@johnxnguyen we've run into a bug which is present on 0.29, but not present on 0.30:

If you try to render a single tick (`) on 0.30.2 with the following C code:

char *content = "`";
int opts = 0;

cmark_node *doc = cmark_parse_document(content, strlen(content), opts);
printf("%d, %d\n", doc->start_column, doc->end_column);
printf("%d, %d\n", doc->first_child->start_column, doc->first_child->end_column);
printf("%d, %d\n", doc->first_child->first_child->start_column, doc->first_child->first_child->end_column);

you get:

1, 1
1, 1
1, 1

as expected, but if you do so with 0.29 (Down's current version which is 3 years old) you get:

1, 1
1, 1
2, 2

which exceeds the document bounds and depending on what you're doing with the AST you'll experience crashes

Parth commented 2 years ago

here is the tree visualized in the xcode debugger: image

Parth commented 2 years ago

if you need it here is what the debug visitor sees:

Document
    ↳ Paragraph
        ↳ Text - `

(which is fine)

Parth commented 2 years ago

Here is a small C program you can use for testing:

bugqmark.zip

if you go into the cmark folder and checkout the most recent commit and regen the libs you'll find that the problem goes away and we're returned valid ranges.

Parth commented 2 years ago

Thanks for lending a hand with the C code @steverusso

Parth commented 2 years ago

I updated on my fork, and everything seems to be working fine, will report back as I explore more: https://github.com/Parth/Down