Code Monkey home page Code Monkey logo

Comments (1)

u5surf avatar u5surf commented on September 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.