aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-02-13 01:02:12 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-02-13 01:02:12 +0100
commitf63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65 (patch)
treedce906c3cce2e564e2f2b218478bfc7dd5047c99
parent542a6d37c5b7675f1c80dcc47a5413ffa76a425b (diff)
downloadblogc-f63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65.tar.gz
blogc-f63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65.tar.bz2
blogc-f63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65.zip
content-parser: fixed bug that parsed text with '!' + link as image
-rw-r--r--src/content-parser.c12
-rw-r--r--tests/check_content_parser.c14
2 files changed, 22 insertions, 4 deletions
diff --git a/src/content-parser.c b/src/content-parser.c
index ccb96ef..a334d28 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -231,11 +231,15 @@ blogc_content_parse_inline(const char *src)
break;
case '!':
- if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
- break;
- }
if (state == LINK_CLOSED) {
+ if (open_code || open_code_double) {
+ b_string_append_c(rv, c);
+ break;
+ }
+ if (!is_last && src[current + 1] != '[') {
+ b_string_append_c(rv, c);
+ break;
+ }
state = LINK_IMAGE;
is_image = true;
start_state = current;
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index 970ec5c..e8e412a 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -1360,6 +1360,10 @@ test_content_parse_inline(void **state)
assert_non_null(html);
assert_string_equal(html, "<em>bola</em>");
free(html);
+ html = blogc_content_parse_inline("bola!");
+ assert_non_null(html);
+ assert_string_equal(html, "bola!");
+ free(html);
}
@@ -1475,6 +1479,10 @@ 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!](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]\n(http://example.org/)\n");
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
@@ -1491,6 +1499,12 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola(2)[3]**!\\</code></a>\n");
free(html);
+ html = blogc_content_parse_inline("test suite!)\n"
+ "depends on [cmocka](http://cmocka.org/), though.\n");
+ assert_non_null(html);
+ assert_string_equal(html, "test suite!)\n"
+ "depends on <a href=\"http://cmocka.org/\">cmocka</a>, though.\n");
+ free(html);
// "invalid"
html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n");
assert_non_null(html);