Skip to content
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

m.route.param() omits trailing slash on three-dots pattern #2763

Closed
FeroxTL opened this issue Apr 14, 2022 · 3 comments
Closed

m.route.param() omits trailing slash on three-dots pattern #2763

FeroxTL opened this issue Apr 14, 2022 · 3 comments
Assignees
Labels
Type: Breaking Change For any feature request or suggestion that could reasonably break existing code Type: Bug For bugs and any other unexpected breakage

Comments

@FeroxTL
Copy link

FeroxTL commented Apr 14, 2022

In my project I'm trying to fetch some dynamic path data, so I've decided to store path info as an url parameter. While doing this I've noticed, that m.route.param(key) returns value without trailing slash (even if it was provided in the url).

That is the example:

m.route(document.body, "/list/static/index.css", {
  "/list/:path...": {
    view: function(vnode) {
      console.log("route.get():", m.route.get());
      console.log("m.route.param():", m.route.param());
    }
  },
});

So if you navigate to /#!/list/static/index.css the output would be correct:

route.get(): /list/static/index.css
m.route.param(): Object { path: "static/index.css" }

But if you navigate to some directory like /#!/list/static/ the trailing slash in the output would be truncated:

route.get(): /list/static/
m.route.param(): Object { path: "static" }

I expect m.route.param("path") should return "static/" -- one with trailing slash

Mithril.js version: [email protected]

Browser and OS:
Same result in latest chrome (v100) and firefox (v91.8)

Context

I've played around and come to some workarounds:

  1. Write custom router and make regex to parse path argument
  2. Move some arguments to url query params, but it looks ugly
@FeroxTL FeroxTL added the Type: Bug For bugs and any other unexpected breakage label Apr 14, 2022
@StephanHoyer
Copy link
Member

Can confirm this with a test. Thanks for reporting.

@StephanHoyer
Copy link
Member

seems like this line causes it.

Removing it solves the issue and only results in one failing test which can be solved easily?

What do you think @dead-claudia?

@dead-claudia
Copy link
Member

dead-claudia commented Apr 18, 2022

@StephanHoyer Let's hold the fix for v3. The behavior's well-defined as-is: the path has all unnecessary slashes removed, and trailing slashes are considered redundant. Developers may already be relying on the lack of a trailing slash currently, so we should continue to honor it.

We should call this out in the docs if it isn't already.

Edit: The mismatch is a bug, but we could offer that as a supported escape hatch until v3.

@dead-claudia dead-claudia added the Type: Breaking Change For any feature request or suggestion that could reasonably break existing code label Apr 18, 2022
barneycarroll pushed a commit that referenced this issue Jun 10, 2022
 [skip ci]

Release Artifacts for v2.2.0

 [skip ci]

Move the chat to Zulip (#2771)

Release Artifacts for v2.2.1

 [skip ci]

Fix malformed image tag

Turn README images from plain HTML to markdown (#2773)

Release Artifacts for v2.2.2

 [skip ci]

allow trailing slash for routes - fixes #2763

Kick promise polyfill

Remove a stale comment

This hasn't been true since v2.0

Kick jsonp - fixes #2682

inline obsolete factory

Add missing prerelease branch target.

Without specifying target:master the prerelease version calculation would be incorrect.

implement m.domFor() and use it internally to move and remove nodes. Fix #2780

Address review comments, linter and build concerns

Rename dom-for in file paths to domFor

Revert "Rename dom-for in file paths to domFor"

This reverts commit 5ab2752.

Rename dom-for in file paths to domFor

Simplify domFor logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking Change For any feature request or suggestion that could reasonably break existing code Type: Bug For bugs and any other unexpected breakage
Projects
None yet
Development

No branches or pull requests

3 participants