diff --git a/api_test/main.c b/api_test/main.c index 83afbff0c..9b7ba4199 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -837,11 +837,11 @@ static void numeric_entities(test_batch_runner *runner) { "Valid numeric entity 0x10FFFF"); test_md_to_html(runner, "�", "

" UTF8_REPL "

\n", "Invalid numeric entity 0x110000"); - test_md_to_html(runner, "�", "

" UTF8_REPL "

\n", + test_md_to_html(runner, "�", "

�

\n", "Invalid numeric entity 0x80000000"); - test_md_to_html(runner, "�", "

" UTF8_REPL "

\n", + test_md_to_html(runner, "�", "

�

\n", "Invalid numeric entity 0xFFFFFFFF"); - test_md_to_html(runner, "�", "

" UTF8_REPL "

\n", + test_md_to_html(runner, "�", "

�

\n", "Invalid numeric entity 99999999"); test_md_to_html(runner, "&#;", "

&#;

\n", diff --git a/src/inlines.c b/src/inlines.c index 2a8424282..263a39b26 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -784,13 +784,18 @@ static cmark_node *handle_backslash(subject *subj) { static cmark_node *handle_entity(subject *subj) { cmark_strbuf ent = CMARK_BUF_INIT(subj->mem); bufsize_t len; + int length_limit = 256; advance(subj); len = houdini_unescape_ent(&ent, subj->input.data + subj->pos, subj->input.len - subj->pos); - if (len == 0) + if (peek_char(subj) == '#') { + length_limit = 9; // includes #, optional x for hex, and ; + } + + if (len <= 0 || len > length_limit) return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("&")); subj->pos += len;