more incomplete slug pattern tests
This commit is contained in:
parent
a6be7f5061
commit
17b4201197
3 changed files with 28 additions and 41 deletions
|
@ -501,6 +501,10 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
|
||||||
// there are two more slugs, we should break them into several parts
|
// there are two more slugs, we should break them into several parts
|
||||||
char *errstr = NULL;
|
char *errstr = NULL;
|
||||||
int slug_cnt = slug_count(path, path_len, &errstr);
|
int slug_cnt = slug_count(path, path_len, &errstr);
|
||||||
|
if (errstr) {
|
||||||
|
printf("Can not insert path '%s'. Error: %s\n", path, errstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( slug_cnt > 1 ) {
|
if ( slug_cnt > 1 ) {
|
||||||
int slug_len;
|
int slug_len;
|
||||||
|
|
43
src/slug.c
43
src/slug.c
|
@ -137,7 +137,7 @@ r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **err
|
||||||
|
|
||||||
if (state > 0) {
|
if (state > 0) {
|
||||||
if (errstr) {
|
if (errstr) {
|
||||||
asprintf(errstr, "incomplete slug pattern. PATH (%d): '%s', OFFSET: %ld, STATE: %d", needle_len, needle, p - needle, state);
|
asprintf(errstr, "Incomplete slug pattern. PATH (%d): '%s', OFFSET: %ld, STATE: %d", needle_len, needle, p - needle, state);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -145,45 +145,6 @@ r3_slug_t * r3_slug_parse(char *needle, int needle_len, char *offset, char **err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
int slug_count2(char * needle, int needle_len, char **errstr) {
|
|
||||||
// r3_slug_t * s = r3_slug_parse(needle, needle_len, needle);
|
|
||||||
|
|
||||||
|
|
||||||
int cnt = 0;
|
|
||||||
int state = 0;
|
|
||||||
char * p = (char*) needle;
|
|
||||||
while( (p-needle) < len) {
|
|
||||||
|
|
||||||
if (*p == '\\' ) {
|
|
||||||
p++; p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == 1 && *p == '}') {
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
if ( *p == '{' ) {
|
|
||||||
state++;
|
|
||||||
} else if ( *p == '}' ) {
|
|
||||||
state--;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
};
|
|
||||||
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
|
|
||||||
if (state != 0) {
|
|
||||||
if (errstr) {
|
|
||||||
asprintf(errstr, "incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* provide a quick way to count slugs, simply search for '{'
|
* provide a quick way to count slugs, simply search for '{'
|
||||||
*/
|
*/
|
||||||
|
@ -211,7 +172,7 @@ int slug_count(const char * needle, int len, char **errstr) {
|
||||||
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
|
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
|
||||||
if (state != 0) {
|
if (state != 0) {
|
||||||
if (errstr) {
|
if (errstr) {
|
||||||
asprintf(errstr, "incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
|
asprintf(errstr, "Incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,27 @@ START_TEST (test_compile)
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
START_TEST (test_incomplete_slug_path)
|
||||||
|
{
|
||||||
|
node * n = r3_tree_create(10);
|
||||||
|
|
||||||
|
// r3_tree_insert_path(n, "/foo-{user}-{id}", NULL, NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{3", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{3}", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{3}}/{", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{3}}/{a", NULL);
|
||||||
|
r3_tree_insert_path(n, "/post/{handle:\\d{3}}/{a}", NULL);
|
||||||
|
|
||||||
|
r3_tree_free(n);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_pcre_patterns_insert)
|
START_TEST (test_pcre_patterns_insert)
|
||||||
{
|
{
|
||||||
node * n = r3_tree_create(10);
|
node * n = r3_tree_create(10);
|
||||||
|
@ -387,6 +408,7 @@ Suite* r3_suite (void) {
|
||||||
tcase_add_test(tcase, test_pcre_patterns_insert);
|
tcase_add_test(tcase, test_pcre_patterns_insert);
|
||||||
tcase_add_test(tcase, test_pcre_patterns_insert_2);
|
tcase_add_test(tcase, test_pcre_patterns_insert_2);
|
||||||
tcase_add_test(tcase, test_pcre_patterns_insert_3);
|
tcase_add_test(tcase, test_pcre_patterns_insert_3);
|
||||||
|
tcase_add_test(tcase, test_incomplete_slug_path);
|
||||||
tcase_set_timeout(tcase, 30);
|
tcase_set_timeout(tcase, 30);
|
||||||
|
|
||||||
suite_add_tcase(suite, tcase);
|
suite_add_tcase(suite, tcase);
|
||||||
|
|
Loading…
Reference in a new issue