From 39fc24e3fad073bed25d78b6febb33f37b57dce5 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 01:05:57 +0800 Subject: [PATCH] fix pattern compiler --- src/node.c | 6 ++---- tests/check_slug.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/node.c b/src/node.c index bc33da7..2bbbe7c 100644 --- a/src/node.c +++ b/src/node.c @@ -163,9 +163,6 @@ int r3_tree_compile_patterns(node * n, char **errstr) { p = cpat; - strncat(p, "^", 1); - p++; - edge *e = NULL; int opcode_cnt = 0; for ( int i = 0 ; i < n->edge_len ; i++ ) { @@ -179,7 +176,8 @@ int r3_tree_compile_patterns(node * n, char **errstr) { char * slug_pat = slug_compile(e->pattern, e->pattern_len); strcat(p, slug_pat); } else { - strncat(p++,"(", 1); + strncat(p,"^(", 2); + p += 2; strncat(p, e->pattern, e->pattern_len); p += e->pattern_len; diff --git a/tests/check_slug.c b/tests/check_slug.c index ca42f85..f916c3a 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -88,7 +88,7 @@ START_TEST (test_slug_count) ck_assert_int_eq( slug_count(pattern, strlen(pattern), NULL), 2 ); char * pattern2 = "/user/{name:\\d{3}}/to/{id}"; - ck_assert_int_eq( slug_count(pattern2, strlen(pattern), NULL), 2 ); + ck_assert_int_eq( slug_count(pattern2, strlen(pattern2), NULL), 2 ); } END_TEST