aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-02-21 04:58:13 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-02-21 05:01:13 +0100
commit31d376735ab2aaaed0934edcce676113f83a7de7 (patch)
tree3afb9cfd7805f4da4ccb0fca203e4e693c32e1f5
parent9d5dd44c68aefa006d06fbff55756a070a84b55b (diff)
downloadblogc-31d376735ab2aaaed0934edcce676113f83a7de7.tar.gz
blogc-31d376735ab2aaaed0934edcce676113f83a7de7.tar.bz2
blogc-31d376735ab2aaaed0934edcce676113f83a7de7.zip
content-parser: fixed parser bug when handling links
do not handle something like this as a valid link: [asd] asd (asd)
-rw-r--r--src/content-parser.c13
-rw-r--r--tests/check_content_parser.c12
2 files changed, 23 insertions, 2 deletions
diff --git a/src/content-parser.c b/src/content-parser.c
index a334d28..9d4adf6 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -161,6 +161,16 @@ blogc_content_parse_inline(const char *src)
if (c != ' ' && c != '\n' && c != '\r')
spaces = 0;
+ if (state == LINK_TEXT_CLOSE && c != ' ' && c != '\n' && c != '\r' &&
+ c != '(')
+ {
+ b_string_append_c(rv, src[start_state]);
+ tmp = blogc_content_parse_inline(src + start_state + 1);
+ b_string_append(rv, tmp);
+ // no need to free here, we will exit the loop!
+ break;
+ }
+
switch (c) {
case '\\':
@@ -390,8 +400,7 @@ blogc_content_parse_inline(const char *src)
b_string_append_c(rv, src[start_state]);
tmp = blogc_content_parse_inline(src + start_state + 1);
b_string_append(rv, tmp);
- free(tmp);
- tmp = NULL;
+ // no need to free here, its the last iteration
}
current++;
}
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index e8e412a..73bbe9b 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -1487,6 +1487,14 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
free(html);
+ html = blogc_content_parse_inline("[bola]\r\n(http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
+ free(html);
+ html = blogc_content_parse_inline("[bola] \r\n (http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
+ free(html);
html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n");
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bo\nla</a>\n");
@@ -1505,6 +1513,10 @@ test_content_parse_inline_link(void **state)
assert_string_equal(html, "test suite!)\n"
"depends on <a href=\"http://cmocka.org/\">cmocka</a>, though.\n");
free(html);
+ html = blogc_content_parse_inline("asd [bola]chunda(1234)");
+ assert_non_null(html);
+ assert_string_equal(html, "asd [bola]chunda(1234)");
+ free(html);
// "invalid"
html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n");
assert_non_null(html);