From df2fce3c46179a0c7ec7c24663e855ef2cb4a776 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 27 Feb 2024 13:20:14 +0000 Subject: [PATCH 1/3] Avoid looping indefinitely when sub-router doesn't match --- crates/sdk/src/queries/router.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/sdk/src/queries/router.rs b/crates/sdk/src/queries/router.rs index 25a55ecf7f..d2e612ac85 100644 --- a/crates/sdk/src/queries/router.rs +++ b/crates/sdk/src/queries/router.rs @@ -126,6 +126,10 @@ macro_rules! try_match_segments { ); } )* + + return Err( + $crate::queries::router::Error::WrongPath($request.path.clone())) + .into_storage_result(); }; // Terminal tail call, invoked after when all the args in the current From ebc89e6375281113db481ca1534e6100ca74e589 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 27 Feb 2024 13:32:33 +0000 Subject: [PATCH 2/3] Add router regression test --- crates/sdk/src/queries/router.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/sdk/src/queries/router.rs b/crates/sdk/src/queries/router.rs index d2e612ac85..36e0be7d8c 100644 --- a/crates/sdk/src/queries/router.rs +++ b/crates/sdk/src/queries/router.rs @@ -1044,6 +1044,25 @@ mod test { let result = TEST_RPC.handle(ctx, &request); assert!(result.is_err()); + // Test request with another invalid path. + // The key difference here is that we are testing + // an invalid path in a nested segment. + let request = RequestQuery { + path: "/b/4".to_owned(), + data: Default::default(), + height: block::Height::from(0_u32), + prove: Default::default(), + }; + let ctx = RequestCtx { + event_log: &client.event_log, + wl_storage: &client.wl_storage, + vp_wasm_cache: (), + tx_wasm_cache: (), + storage_read_past_height_limit: None, + }; + let result = TEST_RPC.handle(ctx, &request); + assert!(result.is_err()); + // Test request with a non-ascii path let request = RequestQuery { path: "ÀÁõö÷øùúûüýþÿ".to_owned(), From 23901a34c83e7f28f02b76954d1d0d45f2774ea4 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 27 Feb 2024 13:37:13 +0000 Subject: [PATCH 3/3] Changelog for #2739 --- .changelog/unreleased/bug-fixes/2739-router-no-pat-match.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/2739-router-no-pat-match.md diff --git a/.changelog/unreleased/bug-fixes/2739-router-no-pat-match.md b/.changelog/unreleased/bug-fixes/2739-router-no-pat-match.md new file mode 100644 index 0000000000..00ebc693c9 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/2739-router-no-pat-match.md @@ -0,0 +1,2 @@ +- Bail from router if a nester router segment is not matched. + ([\#2739](https://github.com/anoma/namada/pull/2739)) \ No newline at end of file