aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/content-parser.c18
-rw-r--r--tests/check_content_parser.c34
2 files changed, 48 insertions, 4 deletions
diff --git a/src/content-parser.c b/src/content-parser.c
index 59e337e..f5450d6 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -405,6 +405,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
size_t eend = 0;
size_t real_end = 0;
+ bool no_jump = false;
+
unsigned int header_level = 0;
char *prefix = NULL;
size_t prefix_len = 0;
@@ -616,6 +618,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
prefix = NULL;
b_slist_free_full(lines, free);
lines = NULL;
+ if (is_last) {
+ free(tmp);
+ tmp = NULL;
+ goto para;
+ }
}
free(tmp);
tmp = NULL;
@@ -677,6 +684,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
lines = NULL;
free(tmp);
tmp = NULL;
+ if (is_last)
+ goto para;
break;
}
free(tmp);
@@ -836,6 +845,8 @@ hr:
break;
}
state = CONTENT_PARAGRAPH;
+ if (is_last)
+ goto para;
break;
case CONTENT_ORDERED_LIST_SPACE:
@@ -947,8 +958,15 @@ hr:
break;
case CONTENT_PARAGRAPH_END:
+ no_jump = true;
para:
if (c == '\n' || c == '\r' || is_last) {
+ if (!no_jump && is_last) {
+ if (c == '\n' || c == '\r')
+ end = src_len - 1;
+ else
+ end = src_len;
+ }
tmp = b_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
b_string_append_printf(rv, "<p>%s</p>%s", parsed,
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index 994e900..dc3485e 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -1135,6 +1135,14 @@ test_content_parse_invalid_blockquote(void **state)
"&gt; bola\n"
"&gt; foo</p>\n");
free(html);
+ html = blogc_content_parse(
+ "> asd\n"
+ "> bola", NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>&gt; asd\n"
+ "&gt; bola</p>\n");
+ free(html);
}
@@ -1151,6 +1159,16 @@ test_content_parse_invalid_code(void **state)
" bola\n"
" foo</p>\n");
free(html);
+ html = blogc_content_parse(
+ " asd\n"
+ " bola\n"
+ " foo", NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p> asd\n"
+ " bola\n"
+ " foo</p>\n");
+ free(html);
}
@@ -1196,7 +1214,8 @@ test_content_parse_invalid_unordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
- "1. qwe</p>\n");
+ "1. qwe"
+ "</p>\n");
free(html);
html = blogc_content_parse(
"* asd\n"
@@ -1204,7 +1223,8 @@ test_content_parse_invalid_unordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
- "1. qwe</p>\n");
+ "1. qwe"
+ "</p>\n");
free(html);
html = blogc_content_parse(
"chunda\n"
@@ -1250,7 +1270,8 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe</p>\n");
+ "<em> qwe"
+ "</p>\n");
free(html);
html = blogc_content_parse(
"1. asd\n"
@@ -1258,7 +1279,8 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
- "<em> qwe</p>\n");
+ "<em> qwe"
+ "</p>\n");
free(html);
html = blogc_content_parse(
"chunda\n"
@@ -1303,6 +1325,10 @@ test_content_parse_invalid_ordered_list(void **state)
assert_non_null(html);
assert_string_equal(html, "<p>1.</p>\n");
free(html);
+ html = blogc_content_parse("1 ", NULL);
+ assert_non_null(html);
+ assert_string_equal(html, "<p>1 </p>\n");
+ free(html);
}