diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-11-04 01:28:52 -0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-11-04 01:28:52 -0200 |
commit | 37850db5081e26a26f05d062497811b864953778 (patch) | |
tree | 3b77ffdb176ce2f125142bf7242c8e3dcba9f90d | |
parent | 0fe9ed29207c428deda6c960c81359113f1d3384 (diff) | |
download | blogc-37850db5081e26a26f05d062497811b864953778.tar.gz blogc-37850db5081e26a26f05d062497811b864953778.tar.bz2 blogc-37850db5081e26a26f05d062497811b864953778.zip |
Revert "content-parser: allow directive params with variable prefix"
This reverts commit d29c85ef1751cb46c579b3292f676605d9f86951.
-rw-r--r-- | src/content-parser.c | 47 | ||||
-rw-r--r-- | tests/check_content_parser.c | 47 |
2 files changed, 24 insertions, 70 deletions
diff --git a/src/content-parser.c b/src/content-parser.c index 042f308..f451587 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -70,7 +70,6 @@ typedef enum { CONTENT_DIRECTIVE_COLON, CONTENT_DIRECTIVE_ARGUMENT_START, CONTENT_DIRECTIVE_ARGUMENT, - CONTENT_DIRECTIVE_PARAM_PREFIX_START, CONTENT_DIRECTIVE_PARAM_PREFIX, CONTENT_DIRECTIVE_PARAM_KEY_START, CONTENT_DIRECTIVE_PARAM_KEY, @@ -417,6 +416,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt) size_t end = 0; size_t eend = 0; size_t real_end = 0; + size_t spaces = 0; bool no_jump = false; @@ -523,7 +523,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt) case CONTENT_EXCERPT_OR_DIRECTIVE: if (c == '.') break; - if ((c == ' ' || c == '\t') && current - start == 2) { + if (c == ' ' && current - start == 2) { state = CONTENT_DIRECTIVE_NAME_START; if (is_last) goto para; @@ -1006,18 +1006,16 @@ hr: break; case CONTENT_DIRECTIVE_ARGUMENT_START: - if (c == ' ' || c == '\t') { + if (c == ' ') { if (is_last) goto param_end; break; } if (c == '\n' || c == '\r' || is_last) { - state = CONTENT_DIRECTIVE_PARAM_PREFIX_START; + state = CONTENT_DIRECTIVE_PARAM_PREFIX; directive_argument = NULL; if (is_last) goto param_end; - else - start2 = current + 1; break; } start2 = current; @@ -1026,32 +1024,29 @@ hr: case CONTENT_DIRECTIVE_ARGUMENT: if (c == '\n' || c == '\r' || is_last) { - state = CONTENT_DIRECTIVE_PARAM_PREFIX_START; + spaces = 0; + state = CONTENT_DIRECTIVE_PARAM_PREFIX; end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); free(directive_argument); directive_argument = b_strndup(src + start2, end - start2); if (is_last) goto param_end; - else - start2 = current + 1; } break; - case CONTENT_DIRECTIVE_PARAM_PREFIX_START: - if (is_last) - goto para; - if (c == ' ' || c == '\t') - break; - prefix = b_strndup(src + start2, current - start2); - state = CONTENT_DIRECTIVE_PARAM_PREFIX; - current--; - break; - case CONTENT_DIRECTIVE_PARAM_PREFIX: - if (c == ' ' || c == '\t') + if (c == ' ') { + spaces++; + break; + } + if ((c == '\n' || c == '\r') && spaces == 0) { + state = CONTENT_DIRECTIVE_PARAM_END; + if (is_last) + goto param_end; break; - if (c == ':' && b_str_starts_with(src + start2, prefix)) { + } + if (c == ':' && spaces == 3) { state = CONTENT_DIRECTIVE_PARAM_KEY_START; break; } @@ -1088,7 +1083,7 @@ hr: case CONTENT_DIRECTIVE_PARAM_VALUE_START: if (is_last) goto para; - if (c == ' ' || c == '\t') + if (c == ' ') break; start2 = current; state = CONTENT_DIRECTIVE_PARAM_VALUE; @@ -1105,8 +1100,6 @@ hr: b_strndup(src + start2, end - start2)); free(directive_key); directive_key = NULL; - if (!is_last) - start2 = current + 1; } if (!is_last) break; @@ -1127,12 +1120,11 @@ param_end: directive_argument = NULL; b_trie_free(directive_params); directive_params = NULL; - free(prefix); - prefix = NULL; break; } - if (c == ' ' || c == '\t') { + if (c == ' ') { start2 = current; + spaces = 1; state = CONTENT_DIRECTIVE_PARAM_PREFIX; break; } @@ -1184,7 +1176,6 @@ para: free(directive_argument); free(directive_key); b_trie_free(directive_params); - free(prefix); return b_string_free(rv, false); } diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index dfb1ffb..8bd16ec 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1129,7 +1129,7 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, "qwe"); html = blogc_content_parse( ".. bola::\r\n" - "\t:asd: qwe\r\n", + " :asd: qwe\r\n", NULL); assert_non_null(html); assert_string_equal(html, @@ -1145,8 +1145,8 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, "vbn"); html = blogc_content_parse( ".. bola::\n" - "\t\t:asd: qwe\n" - "\t\t:zxc: vbn", + " :asd: qwe\n" + " :zxc: vbn", NULL); assert_non_null(html); assert_string_equal(html, @@ -1162,8 +1162,8 @@ test_content_parse_directive(void **state) will_return(__wrap_blogc_directive_loader, "vbn"); html = blogc_content_parse( ".. bola::\n" - " :asd: qwe\n" - " :zxc: vbn\n", + " :asd: qwe\n" + " :zxc: vbn\n", NULL); assert_non_null(html); assert_string_equal(html, @@ -1412,43 +1412,6 @@ test_content_parse_directive(void **state) "CHUNDA\n" "<p>bola</p>\r\n"); free(html); - - will_return(__wrap_blogc_directive_loader, "bola"); - will_return(__wrap_blogc_directive_loader, "chunda"); - will_return(__wrap_blogc_directive_loader, 3); - will_return(__wrap_blogc_directive_loader, "asd"); - will_return(__wrap_blogc_directive_loader, "qwe"); - will_return(__wrap_blogc_directive_loader, "ert"); - will_return(__wrap_blogc_directive_loader, "zxvc"); - will_return(__wrap_blogc_directive_loader, "qwe"); - will_return(__wrap_blogc_directive_loader, "bola"); - will_return(__wrap_blogc_directive_loader, "bolao"); - will_return(__wrap_blogc_directive_loader, "chund"); - will_return(__wrap_blogc_directive_loader, 2); - will_return(__wrap_blogc_directive_loader, "asd"); - will_return(__wrap_blogc_directive_loader, "qwe"); - will_return(__wrap_blogc_directive_loader, "ert"); - will_return(__wrap_blogc_directive_loader, "zxvc"); - html = blogc_content_parse( - "# foo\r\n" - "\r\n" - ".. bola:: chunda\r\n" - " :asd: qwe\r\n" - " :ert: zxvc\r\n" - " :qwe: bola\r\n" - "\r\n" - ".. bolao:: chund\r\n" - " :asd: qwe\r\n" - " :ert: zxvc\r\n" - "\r\n" - "bola", NULL); - assert_non_null(html); - assert_string_equal(html, - "<h1 id=\"foo\">foo</h1>\r\n" - "CHUNDA\n" - "CHUNDA\n" - "<p>bola</p>\r\n"); - free(html); } |