-
-
Notifications
You must be signed in to change notification settings - Fork 13
Allow querying the number of routes in URITemplateRouter
#2339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2318,3 +2318,62 @@ TEST_F(URITemplateRouterViewTest, | |
| EXPECT_ROUTER_MATCH(restored, "/users", 1, 20, captures); | ||
| EXPECT_EQ(captures.size(), 0); | ||
| } | ||
|
|
||
| TEST_F(URITemplateRouterViewTest, size_empty_router) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| { | ||
| const sourcemeta::core::URITemplateRouter router; | ||
| sourcemeta::core::URITemplateRouterView::save(router, this->path); | ||
| } | ||
|
|
||
| const sourcemeta::core::URITemplateRouterView restored{this->path}; | ||
| EXPECT_EQ(restored.size(), 0); | ||
| } | ||
|
|
||
| TEST_F(URITemplateRouterViewTest, size_single_route) { | ||
| { | ||
| sourcemeta::core::URITemplateRouter router; | ||
| router.add("/users", 1); | ||
| sourcemeta::core::URITemplateRouterView::save(router, this->path); | ||
| } | ||
|
|
||
| const sourcemeta::core::URITemplateRouterView restored{this->path}; | ||
| EXPECT_EQ(restored.size(), 1); | ||
| } | ||
|
|
||
| TEST_F(URITemplateRouterViewTest, size_multiple_routes) { | ||
| { | ||
| sourcemeta::core::URITemplateRouter router; | ||
| router.add("/users", 1); | ||
| router.add("/users/{id}", 2); | ||
| router.add("/posts", 3); | ||
| router.add("/posts/{id}", 4); | ||
| sourcemeta::core::URITemplateRouterView::save(router, this->path); | ||
| } | ||
|
|
||
| const sourcemeta::core::URITemplateRouterView restored{this->path}; | ||
| EXPECT_EQ(restored.size(), 4); | ||
| } | ||
|
|
||
| TEST_F(URITemplateRouterViewTest, size_duplicate_route_does_not_increase) { | ||
| { | ||
| sourcemeta::core::URITemplateRouter router; | ||
| router.add("/users", 1); | ||
| router.add("/users", 2); | ||
| sourcemeta::core::URITemplateRouterView::save(router, this->path); | ||
| } | ||
|
|
||
| const sourcemeta::core::URITemplateRouterView restored{this->path}; | ||
| EXPECT_EQ(restored.size(), 1); | ||
| } | ||
|
|
||
| TEST_F(URITemplateRouterViewTest, size_with_base_path) { | ||
| { | ||
| sourcemeta::core::URITemplateRouter router{"/v1"}; | ||
| router.add("/users", 1); | ||
| router.add("/posts", 2); | ||
| sourcemeta::core::URITemplateRouterView::save(router, this->path); | ||
| } | ||
|
|
||
| const sourcemeta::core::URITemplateRouterView restored{this->path}; | ||
| EXPECT_EQ(restored.size(), 2); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URITemplateRouterView::size()only bounds-checksnode_countagainst the total buffer size, but doesn’t validatestring_table_offset/arguments_offsetlikematch()/base_path()do. On a partially corrupt blob wherenode_countoverlaps the string table,size()could return a non-zero count even though the view should be considered invalid.Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.