Comments (1)
Hi, I'm interested in this issues. and I've dived in it slightly.
At first, simply(although may be stupidly?), I just added path.trim_end_matches('/');
both router.route
and server.at
.
Of course this test which @sorcix had indicated has succeeded.
diff --git a/src/router.rs b/src/router.rs
index e59e260..36ac513 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -46,6 +46,7 @@ impl<State: Clone + Send + Sync + 'static> Router<State> {
}
pub(crate) fn route(&self, path: &str, method: http_types::Method) -> Selection<'_, State> {
+ let path = path.trim_end_matches('/');
if let Some(Match { handler, params }) = self
.method_map
.get(&method)
diff --git a/src/server.rs b/src/server.rs
index 1e6f8c1..c96f7c1 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -163,6 +163,7 @@ where
/// match or not, which means that the order of adding resources has no
/// effect.
pub fn at<'a>(&'a mut self, path: &str) -> Route<'a, State> {
+ let path = path.trim_end_matches('/');
let router = Arc::get_mut(&mut self.router)
.expect("Registering routes is not possible after the Server has started");
Route::new(router, path.to_owned())
But there are one conventional test which been failed.
Running tests/wildcard.rs (target/debug/deps/wildcard-2df3af0ed73f684a)
running 11 tests
test invalid_segment_error ... ok
test ambiguous_router_wildcard_vs_star ... ok
test multi_wildcard ... ok
test nameless_internal_wildcard2 ... ok
test nameless_internal_wildcard ... ok
test not_found_error ... ok
test nameless_wildcard ... ok
test invalid_wildcard ... FAILED
test wild_last_segment ... ok
test wildcard ... ok
test wild_path ... ok
failures:
---- invalid_wildcard stdout ----
thread 'invalid_wildcard' panicked at 'assertion failed: `(left == right)`
left: `Ok`,
right: `NotFound`', tests/wildcard.rs:102:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
invalid_wildcard
test result: FAILED. 10 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
error: test failed, to rerun pass '--test wildcard'
./tests/wildcard.rs
#[async_std::test]
async fn invalid_wildcard() -> tide::Result<()> {
let mut app = tide::new();
app.at("/echo/*path/:one/").get(echo_path);
assert_eq!(
app.get("/echo/one/two").await?.status(),
StatusCode::NotFound
);
Ok(())
}
Conventionally, server.at has not removed their last slash
which can use to be a last blank segment.
Thus, /echo/*path/:one/
which is used in invalid_wildcard
could be divided echo
, *path
, :one
,
.
/echo/one/two
was recognized as echo
, one
, two
, it returns StatusCode::NotFound cause it cannot be matched echo
, *path
, :one
,
.
Although, my stupidly proposed changes has removed last
segment, in other words segments has been divided echo
, *path
, :one
.
Unfortunately, it can be matched segments. and then it has returned Ok
.
@yoshuawuyts
Could tell us whether last blank segment has necessary or expected expression?
from tide.
Related Issues (20)
- `req.body_json().await?` Get `serde_json::error::Error` HOT 2
- SessionMiddleware and RedisSessionStore HOT 3
- Unexpected Behaviour in 0.17.0-beta.1 HOT 5
- Cookie_string parsed incorrectly when reading an incoming cookie. HOT 4
- dinamycally check allowed origins (or with a regex) HOT 1
- WASM support HOT 2
- How to do RBAC authorization when using tide? HOT 1
- Error messages are not returned HOT 5
- Stop a Tide server (not graceful shutdown) HOT 1
- Support uploads (100 Continue) HOT 4
- Route introspection? HOT 2
- I don't see the code that implements &str for the listen method
- Does tide plan to support http2? HOT 5
- Proposal: Refactor Middleware Execution / Next with Cursors and Async Recursion HOT 1
- Chat link is invalid HOT 1
- serve_dir doesn't seem to work and even panics in some cases HOT 2
- failed to select version 0.17.0 (copied the one given in the doc) and did a cargo run
- Nested endpoints have less priority than wildcards
- Potential security issue HOT 1
- Embed Assets to Binary
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tide.