fix slug compilation

This commit is contained in:
c9s 2014-05-18 14:30:00 +08:00
parent f4bb320470
commit cda897a9a7
3 changed files with 69 additions and 4 deletions

View file

@ -83,8 +83,22 @@ char * compile_slug(char * str, int len)
if ( NULL != (pat = strchr(s1, ':')) ) {
pat++;
// find closing '}'
int cnt = 1;
s2 = pat;
while(s2) {
if (*s2 == '{' )
cnt++;
else if (*s2 == '}' )
cnt--;
if (cnt == 0)
break;
s2++;
}
// this slug contains a pattern
s2 = strchr(pat, '}');
// s2 = strchr(pat, '}');
*o = '(';
o++;

View file

@ -157,3 +157,16 @@
1400389511,11126324.77
1400393822,10834745.34
1400393905,10709222.20
1400394012,10213843.65
1400394020,10789186.08
1400394033,10376120.72
1400394043,10870636.70
1400394050,10627263.79
1400394080,10766286.36
1400394087,10864430.68
1400394095,11008891.52
1400394100,10578167.34
1400394266,10622702.57
1400394385,10413209.43
1400394571,8615372.65
1400394590,10964999.94

1 1400242718 5649455.80
157 1400389511 11126324.77
158 1400393822 10834745.34
159 1400393905 10709222.20
160 1400394012 10213843.65
161 1400394020 10789186.08
162 1400394033 10376120.72
163 1400394043 10870636.70
164 1400394050 10627263.79
165 1400394080 10766286.36
166 1400394087 10864430.68
167 1400394095 11008891.52
168 1400394100 10578167.34
169 1400394266 10622702.57
170 1400394385 10413209.43
171 1400394571 8615372.65
172 1400394590 10964999.94

View file

@ -251,20 +251,55 @@ START_TEST(test_pcre_pattern_simple)
{
match_entry * entry;
entry = match_entry_createl( "/user/123" , strlen("/user/123") );
node * n = r3_tree_create(10);
r3_tree_insert_pathl(n, "/user/{id}", strlen("/user/{id}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, NULL);
r3_tree_compile(n);
r3_tree_dump(n, 0);
node *matched;
matched = r3_tree_match(n, "/user/123", strlen("/user/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
}
END_TEST
START_TEST(test_pcre_pattern_more)
{
match_entry * entry;
entry = match_entry_createl( "/user/123" , strlen("/user/123") );
node * n = r3_tree_create(10);
r3_tree_insert_pathl(n, "/user", strlen("/user"), NULL, NULL);
r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user2/{id:\\d+}", strlen("/user2/{id:\\d+}"), NULL, NULL);
r3_tree_insert_pathl(n, "/user3/{id:\\d{3}}", strlen("/user3/{id:\\d{3}}"), NULL, NULL);
r3_tree_compile(n);
r3_tree_dump(n, 0);
node *matched;
matched = r3_tree_match(n, "/user/123", strlen("/user/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
matched = r3_tree_match(n, "/user2/123", strlen("/user2/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
matched = r3_tree_match(n, "/user3/123", strlen("/user3/123"), entry);
fail_if(matched == NULL);
ck_assert_int_gt(entry->vars->len, 0);
ck_assert_str_eq(entry->vars->tokens[0],"123");
}
END_TEST
START_TEST(test_insert_route)
{
int var1 = 22;
@ -683,6 +718,9 @@ Suite* r3_suite (void) {
tcase_add_test(tcase, test_compile);
tcase_add_test(tcase, test_route_cmp);
tcase_add_test(tcase, test_insert_route);
tcase_add_test(tcase, test_pcre_pattern_simple);
tcase_add_test(tcase, test_pcre_pattern_more);
tcase_add_test(tcase, benchmark_str);