Skip to content

Commit

Permalink
Merge pull request vmg#146 from stevewolter/master
Browse files Browse the repository at this point in the history
Fix issue vmg#125 (formatting in TOCs) and out-of-bounds memory access in tab expansion
  • Loading branch information
mildsunrise committed Dec 1, 2014
2 parents 3afc3ec + 4825466 commit 977e26e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2707,10 +2707,10 @@ static void expand_tabs(hoedown_buffer *ob, const uint8_t *line, size_t size)
size_t org = i;

while (i < size && line[i] != '\t') {
i++;
/* ignore UTF-8 continuation bytes */
if ((line[i] & 0xc0) != 0x80)
tab++;
i++;
}

if (i > org)
Expand Down
4 changes: 2 additions & 2 deletions src/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ toc_header(hoedown_buffer *ob, const hoedown_buffer *content, int level, const h
}

hoedown_buffer_printf(ob, "<a href=\"#toc_%d\">", state->toc_data.header_count++);
if (content) escape_html(ob, content->data, content->size);
if (content) hoedown_buffer_put(ob, content->data, content->size);
HOEDOWN_BUFPUTSL(ob, "</a>\n");
}
}
Expand Down Expand Up @@ -654,7 +654,7 @@ hoedown_html_toc_renderer_new(int nesting_level)
NULL,

NULL,
NULL,
rndr_normal_text,

NULL,
toc_finalize
Expand Down
15 changes: 15 additions & 0 deletions test/Tests/Formatting in Table of Contents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul>
<li>
<a href="#toc_0">Header with special &amp; characters</a>
<ul>
<li>
<a href="#toc_1">With <code>Code</code></a>
<ul>
<li>
<a href="#toc_2">With <em>Emphasis</em></a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
5 changes: 5 additions & 0 deletions test/Tests/Formatting in Table of Contents.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Header with special & characters

## With `Code`

### With *Emphasis*
5 changes: 5 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
"input": "Tests/Escape character.text",
"output": "Tests/Escape character.html"
},
{
"input": "Tests/Formatting in Table of Contents.text",
"output": "Tests/Formatting in Table of Contents.html",
"flags": ["--html-toc", "-t", "3"]
},
{
"input": "Tests/Math.text",
"output": "Tests/Math.html",
Expand Down

0 comments on commit 977e26e

Please sign in to comment.