diff --git a/configure.ac b/configure.ac index 73a7bce..27ffb21 100644 --- a/configure.ac +++ b/configure.ac @@ -90,6 +90,9 @@ AM_CONDITIONAL(ENABLE_GRAPHVIZ, test "x$enable_graphviz" = "xyes") AC_ARG_ENABLE(json, AS_HELP_STRING([--enable-json],[enable json encoder])) if test "x$enable_json" = "xyes"; then + PKG_CHECK_MODULES(JSONC, [json-c]) + AC_SUBST(JSONC_CFLAGS) + AC_SUBST(JSONC_LIBS) AC_DEFINE(ENABLE_JSON, 1, [enable json]) fi AM_CONDITIONAL(ENABLE_JSON, test "x$enable_json" = "xyes") 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/src/str.c b/src/str.c index a3ae55b..98bc687 100644 --- a/src/str.c +++ b/src/str.c @@ -272,6 +272,9 @@ char * slug_compile(const char * str, int len) } o = out; + strncat(o, "^", 1); + o++; + strncat(o, str, s1 - str); // string before slug o += (s1 - str); diff --git a/tests/Makefile.am b/tests/Makefile.am index b734472..98334ed 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,14 +6,13 @@ # endif TESTS = -AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall -AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) -L$(top_builddir) -lr3 -lcheck @CHECK_LIBS@ +AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall +AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS) -L$(top_builddir) -lr3 -lcheck @CHECK_LIBS@ if USE_JEMALLOC AM_CFLAGS += -ljemalloc endif - noinst_HEADERS = \ bench.h \ $(NULL) diff --git a/tests/check_slug.c b/tests/check_slug.c index 36a555a..e943b94 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -25,19 +25,19 @@ START_TEST (test_slug_compile) { char * path = "/user/{id}"; char * c = NULL; - ck_assert_str_eq( c = slug_compile(path, strlen(path) ) , "/user/([^/]+)" ); + ck_assert_str_eq( c = slug_compile(path, strlen(path) ) , "^/user/([^/]+)" ); zfree(c); char * path2 = "/what/{id}-foo"; - ck_assert_str_eq( c = slug_compile(path2, strlen(path2) ) , "/what/([^/]+)-foo" ); + ck_assert_str_eq( c = slug_compile(path2, strlen(path2) ) , "^/what/([^/]+)-foo" ); zfree(c); char * path3 = "-{id}"; - ck_assert_str_eq( c = slug_compile(path3, strlen(path3)), "-([^/]+)" ); + ck_assert_str_eq( c = slug_compile(path3, strlen(path3)), "^-([^/]+)" ); zfree(c); char * path4 = "-{idx:\\d{3}}"; - ck_assert_str_eq( c = slug_compile(path4, strlen(path4)), "-(\\d{3})" ); + ck_assert_str_eq( c = slug_compile(path4, strlen(path4)), "^-(\\d{3})" ); zfree(c); } END_TEST