From cbefb0ffb583a877a082bc336f2d61be7e773a5d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 18 May 2015 19:12:00 -0300 Subject: content-parser: fix and test horizontal rules --- src/content-parser.c | 5 +++- tests/check_content_parser.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/content-parser.c b/src/content-parser.c index aa4db79..f412810 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -548,6 +548,8 @@ blogc_content_parse(const char *src) case CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE: if (c == d) { + if (is_last) + goto hr; state = CONTENT_HORIZONTAL_RULE; break; } @@ -558,9 +560,10 @@ blogc_content_parse(const char *src) break; case CONTENT_HORIZONTAL_RULE: - if (c == d) { + if (c == d && !is_last) { break; } +hr: if (c == '\n' || c == '\r' || is_last) { b_string_append(rv, "
\n"); state = CONTENT_START_LINE; diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 0053051..390d516 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -215,6 +215,64 @@ test_content_parse_code(void **state) } +void +test_content_parse_horizontal_rule(void **state) +{ + char *html = blogc_content_parse("bola\nguda\n\n**"); + assert_non_null(html); + assert_string_equal(html, + "

bola\n" + "guda

\n" + "
\n"); + free(html); + html = blogc_content_parse("bola\nguda\n\n++++"); + assert_non_null(html); + assert_string_equal(html, + "

bola\n" + "guda

\n" + "
\n"); + free(html); + html = blogc_content_parse("bola\nguda\n\n--\n"); + assert_non_null(html); + assert_string_equal(html, + "

bola\n" + "guda

\n" + "
\n"); + free(html); + html = blogc_content_parse("bola\nguda\n\n****\n"); + assert_non_null(html); + assert_string_equal(html, + "

bola\n" + "guda

\n" + "
\n"); + free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "**\n" + "\n" + "chunda\n"); + assert_non_null(html); + assert_string_equal(html, + "

bola

\n" + "
\n" + "

chunda

\n"); + free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "----\n" + "\n" + "chunda\n"); + assert_non_null(html); + assert_string_equal(html, + "

bola

\n" + "
\n" + "

chunda

\n"); + free(html); +} + + void test_content_parse_invalid_header(void **state) { @@ -308,6 +366,7 @@ main(void) unit_test(test_content_parse_html), unit_test(test_content_parse_blockquote), unit_test(test_content_parse_code), + unit_test(test_content_parse_horizontal_rule), unit_test(test_content_parse_invalid_header), unit_test(test_content_parse_invalid_header_empty), unit_test(test_content_parse_invalid_blockquote), -- cgit v1.2.3-18-g5258