branch at the correct position (avoid broken slug)
This commit is contained in:
parent
cd3e98465b
commit
9381ab943c
2 changed files with 21 additions and 1 deletions
14
src/node.c
14
src/node.c
|
@ -217,6 +217,7 @@ rnode * rnode_insert_routel(rnode *tree, char *route, int route_len)
|
|||
n = child;
|
||||
return n;
|
||||
} else if ( dl == e->pattern_len ) { // fully-equal to the pattern of the edge
|
||||
|
||||
char * subroute = route + dl;
|
||||
int subroute_len = route_len - dl;
|
||||
|
||||
|
@ -230,7 +231,18 @@ rnode * rnode_insert_routel(rnode *tree, char *route, int route_len)
|
|||
}
|
||||
|
||||
} else if ( dl < e->pattern_len ) {
|
||||
printf("branch the edge dl: %d\n", dl);
|
||||
// printf("branch the edge dl: %d\n", dl);
|
||||
|
||||
// branch the edge at correct position (avoid broken slugs)
|
||||
char *slug_s = strchr(route, '{');
|
||||
char *slug_e = strchr(route, '}');
|
||||
if ( dl > (slug_s - route) && dl < (slug_e - route) ) {
|
||||
// break before '{'
|
||||
dl = slug_s - route;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* it's partically matched with the pattern,
|
||||
* we should split the end point and make a branch here...
|
||||
*/
|
||||
|
|
|
@ -106,6 +106,14 @@ START_TEST (test_rnode_insert_routel)
|
|||
rnode_insert_routel(n, "/f/id", strlen("/f/id") );
|
||||
rnode_dump(n, 0);
|
||||
|
||||
printf("Inserting /post/{id}\n");
|
||||
rnode_insert_routel(n, "/post/{id}", strlen("/post/{id}") );
|
||||
rnode_dump(n, 0);
|
||||
|
||||
printf("Inserting /post/{handle}\n");
|
||||
rnode_insert_routel(n, "/post/{handle}", strlen("/post/{handle}") );
|
||||
rnode_dump(n, 0);
|
||||
|
||||
/*
|
||||
fail_if(n == NULL, "rnode tree");
|
||||
|
||||
|
|
Loading…
Reference in a new issue