aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/content-parser.c39
-rw-r--r--tests/check_content_parser.c144
2 files changed, 170 insertions, 13 deletions
diff --git a/src/content-parser.c b/src/content-parser.c
index 7781c92..041e96d 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -588,9 +588,15 @@ hr:
parsed = NULL;
}
else {
- state = CONTENT_PARAGRAPH;
+ state = CONTENT_PARAGRAPH_END;
free(tmp);
tmp = NULL;
+ free(prefix);
+ prefix = NULL;
+ b_slist_free_full(lines, free);
+ lines = NULL;
+ if (is_last)
+ goto para;
break;
}
free(tmp);
@@ -634,7 +640,8 @@ hr:
break;
prefix_len = current - start;
state = CONTENT_ORDERED_LIST_START;
- break;
+ if (c != '\n' && c != '\r' && !is_last)
+ break;
case CONTENT_ORDERED_LIST_START:
if (c == '\n' || c == '\r' || is_last) {
@@ -646,19 +653,25 @@ hr:
free(tmp2);
tmp2 = NULL;
if (b_strv_length(tmpv) != 2) {
- state = CONTENT_PARAGRAPH;
- goto err_li;
+ state = CONTENT_PARAGRAPH_END;
+ b_strv_free(tmpv);
+ tmpv = NULL;
+ free(tmp);
+ tmp = NULL;
+ b_slist_free_full(lines, free);
+ lines = NULL;
+ goto para;
}
for (unsigned int i = 0; tmpv[0][i] != '\0'; i++) {
if (!(tmpv[0][i] >= '0' && tmpv[0][i] <= '9')) {
- state = CONTENT_PARAGRAPH;
- goto err_li;
- }
- }
- for (unsigned int i = 0; tmpv[1][i] != '\0'; i++) {
- if (!(tmpv[1][i] == ' ' || tmpv[1][i] == '\t')) {
- state = CONTENT_PARAGRAPH;
- goto err_li;
+ state = CONTENT_PARAGRAPH_END;
+ b_strv_free(tmpv);
+ tmpv = NULL;
+ free(tmp);
+ tmp = NULL;
+ b_slist_free_full(lines, free);
+ lines = NULL;
+ goto para;
}
}
tmp3 = b_strdup(tmp + prefix_len);
@@ -669,7 +682,6 @@ hr:
state = CONTENT_ORDERED_LIST_END;
free(parsed);
parsed = NULL;
-err_li:
b_strv_free(tmpv);
tmpv = NULL;
}
@@ -707,6 +719,7 @@ err_li:
break;
case CONTENT_PARAGRAPH_END:
+para:
if (c == '\n' || c == '\r' || is_last) {
tmp = b_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index ea8de4b..4f46be8 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -378,6 +378,24 @@ test_content_parse_ordered_list(void **state)
"</ol>\n"
"<p>fuuuu</p>\n");
free(html);
+ html = blogc_content_parse(
+ "1.\nasd\n"
+ "2. qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1.\n"
+ "asd</p>\n"
+ "<ol>\n"
+ "<li>qwe</li>\n"
+ "</ol>\n");
+ free(html);
+ html = blogc_content_parse("1.\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<ol>\n"
+ "<li></li>\n"
+ "</ol>\n");
+ free(html);
}
@@ -463,6 +481,130 @@ test_content_parse_invalid_horizontal_rule(void **state)
void
+test_content_parse_invalid_unordered_list(void **state)
+{
+ // more invalid html
+ char *html = blogc_content_parse(
+ "* asd\n"
+ "1. qwe");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p><em> asd\n"
+ "1. qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "* asd\n"
+ "1. qwe\n"
+ "\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p><em> asd\n"
+ "1. qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "* asd\n"
+ "1. qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p><em> asd\n"
+ "1. qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "* asd\n"
+ "1. qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p><em> asd\n"
+ "1. qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "chunda\n"
+ "\n"
+ "* asd\n"
+ "1. qwe\n"
+ "\n"
+ "poi\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>chunda</p>\n"
+ "<p><em> asd\n"
+ "1. qwe</p>\n"
+ "<p>poi</p>\n");
+ free(html);
+}
+
+
+void
+test_content_parse_invalid_ordered_list(void **state)
+{
+ // more invalid html
+ char *html = blogc_content_parse(
+ "1. asd\n"
+ "* qwe");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1. asd\n"
+ "<em> qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "1. asd\n"
+ "* qwe\n"
+ "\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1. asd\n"
+ "<em> qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "1. asd\n"
+ "* qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1. asd\n"
+ "<em> qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "1. asd\n"
+ "* qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1. asd\n"
+ "<em> qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "chunda\n"
+ "\n"
+ "1. asd\n"
+ "* qwe\n"
+ "\n"
+ "poi\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>chunda</p>\n"
+ "<p>1. asd\n"
+ "<em> qwe</p>\n"
+ "<p>poi</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "1 asd\n"
+ "* qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>1 asd\n"
+ "<em> qwe</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "a. asd\n"
+ "2. qwe\n");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>a. asd\n"
+ "2. qwe</p>\n");
+ free(html);
+}
+
+
+void
test_content_parse_inline(void **state)
{
char *html = blogc_content_parse_inline(
@@ -497,6 +639,8 @@ main(void)
unit_test(test_content_parse_invalid_blockquote),
unit_test(test_content_parse_invalid_code),
unit_test(test_content_parse_invalid_horizontal_rule),
+ unit_test(test_content_parse_invalid_unordered_list),
+ unit_test(test_content_parse_invalid_ordered_list),
unit_test(test_content_parse_inline),
};
return run_tests(tests);