8000 UTF-8 characters are not allowed on mount points or catch prefixes · Issue #2862 · rwf2/Rocket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
UTF-8 characters are not allowed on mount points or catch prefixes #2862
Open
@ludverse

Description

@ludverse

Rocket Version

0.5.1

Operating System

Debian Testing (upgraded last week)

Rust Toolchain Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)

What happened?

I'm trying to use URL-encoded chars in my routes and Rocket just responds with 404. Rocket manages to compile with the following test case, but the issue is that, as you can see in the log output:

GET /h%C3%A4cker:
   >> No matching routes for GET /h%C3%A4cker.
   >> No 404 catcher registered. Using Rocket default.

when i make the request to the exact same path as the get macro was defined as, Rocket fails to match my request to my route.

This way I've done it in the test case is a reasonable assumption to how Rocket would handle paths as according to this part of the docs, Origins should be URL-encoded.

Test Case

use rocket::{get, launch, routes};

#[get("/h%C3%A4cker")]
fn serve_hacker() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![serve_hacker])
}

#[cfg(test)]
mod test {
    #[test]
    fn test_hacker_get() {
        use rocket::local::blocking::Client;

        let client = Client::tracked(super::rocket()).expect("valid `Rocket`");

        let response = client.get("/h%C3%A4cker").dispatch();
        assert_eq!(response.into_string().unwrap(), "Hello, world!");
    }
}

Log Output

> ROCKET_LOG_LEVEL=debug cargo test
   Compiling rocket-unicode-issue-test v0.1.0 (/home/ludv/coding/misc/rocket-unicode-issue-test)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 1.11s
     Running unittests src/main.rs (target/debug/deps/rocket_unicode_issue_test-7fb95b3b05290781)

running 1 test
test test::test_hacker_get ... FAILED

failures:

---- test::test_hacker_get stdout ----
-- configuration trace information --
   >> "address" parameter source: rocket::Config::default()
   >> "port" parameter source: rocket::Config::default()
   >> "workers" parameter source: rocket::Config::default()
   >> "max_blocking" parameter source: rocket::Config::default()
   >> "keep_alive" parameter source: rocket::Config::default()
   >> "ident" parameter source: rocket::Config::default()
   >> "ip_header" parameter source: rocket::Config::default()
   >> "limits" parameter source: rocket::Config::default()
   >> "temp_dir" parameter source: rocket::Config::default()
   >> "log_level" parameter source: `ROCKET_` environment variable(s)
   >> "shutdown" parameter source: rocket::Config::default()
   >> "cli_colors" parameter source: rocket::Config::default()
🔧 Configured for debug.
   >> address: 127.0.0.1
   >> port: 8000
   >> workers: 12
   >> max blocking threads: 512
   >> ident: Rocket
   >> IP header: X-Real-IP
   >> limits: bytes = 8KiB, data-form = 2MiB, file = 1MiB, form = 32KiB, json = 1MiB, msgpack = 1MiB, string = 8KiB
   >> temp dir: /tmp
   >> http/2: true
   >> keep-alive: 5s
   >> tls: disabled
   >> shutdown: ctrlc = true, force = true, signals = [SIGTERM], grace = 2s, mercy = 3s
   >> log level: debug
   >> cli colors: true
📬 Routes:
   >> (serve_hacker) GET /h%C3%A4cker
📡 Fairings:
   >> Shield (liftoff, response, singleton)
🛡️  Shield:
   >> X-Frame-Options: SAMEORIGIN
   >> Permissions-Policy: interest-cohort=()
   >> X-Content-Type-Options: nosniff
🚀 Rocket has launched locally
GET /h%C3%A4cker:
   >> No matching routes for GET /h%C3%A4cker.
   >> No 404 catcher registered. Using Rocket default.
thread 'test::test_hacker_get' panicked at src/main.rs:22:9:
assertion `left == right` failed
  left: "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\">\n    <meta name=\"color-scheme\" content=\"light dark\">\n    <title>404 Not Found</title>\n</head>\n<body align=\"center\">\n    <div role=\"main\" align=\"center\">\n        <h1>404: Not Found</h1>\n        <p>The requested resource could not be found.</p>\n        <hr />\n    </div>\n    <div role=\"contentinfo\" align=\"center\">\n        <small>Rocket</small>\n    </div>\n</body>\n</html>"
 right: "Hello, world!"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test::test_hacker_get

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `--bin rocket-unicode-issue-test`
Program exited erroneously with code 101

Additional Context

No response

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    deficiencySomething doesn't work as well as it could

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0