question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`#` gets replaced with `/` in url

See original GitHub issue

I’m using choo and just found this really weird behavior, which looks like a bug. When you open a url that contains a #, it gets replaced with /, which causes a route not to match. e.g. /test#foo is transformed to /test/foo

I would have expected that /test#foo matches the route /test. To fix the issue we could change the suffix regex on line 10 to include the #. And btw, there’s no need to escape ? in character sets.

@@ -7,7 +7,7 @@ var isLocalFile = (/file:\/\//.test(typeof window === 'object' &&
 var electron = '^(file:\/\/|\/)(.*\.html?\/?)?'
 var protocol = '^(http(s)?(:\/\/))?(www\.)?'
 var domain = '[a-zA-Z0-9-_\.]+(:[0-9]{1,5})?(\/{1})?'
-var qs = '[\?].*$'
+var qs = '[?#].*$'
 /* eslint-enable no-useless-escape */
 
 var stripElectron = new RegExp(electron)

How to reproduce it

// launch with `bankai start ./test.js` and open https://localhost:8080/test#foo
const choo = require('choo')()
const html = require('bel')

choo.route('/test', function (state) {
  return html`
    <body>
      This route does not match: /test#foo<br>
      state.route: ${state.route}<br>
      state.href: ${state.href}
    </body>
  `
})

choo.route('/test/foo', function (state) {
  return html`
    <body>
      This route matches: /test#foo<br>
      state.route: ${state.route}<br>
      state.href: ${state.href}
    </body>
  `
})

choo.mount('body')

image

And sorry for writing on christmas 😆. I just got home and began coding 🤦‍♂️ .

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcbachmanncommented, Dec 28, 2017

No problem, it just was very unexpected. I spent some time on it to figure out what happened. Thanks, the docs PR is how I found that functionality.

Separate from that, I do agree that having routes like /foo/bar#baz should work. Perhaps we could do some work on that too?

Yep, maybe with another match when the hash is present.

1reaction
yoshuawuytscommented, Dec 28, 2017

@marcbachmann heya, yeah sorry this isn’t working the way you’d hoped. The hash routing has always been a bit of a tricky one.

We merged our routing docs today. Could you perhaps take a look to see if the information you were missing now exists? That’d be a great help so that nobody runs into this in the future!

Separate from that, I do agree that having routes like /foo/bar#baz should work. Perhaps we could do some work on that too?

Thanks heaps for the very detailed issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The url get replaced by space character %20 - Stack Overflow
You can use urlencode to encode your url. The decoding will happen automatically, and can get the value from $_GET.
Read more >
HTML URL Encoding Reference - W3Schools
Character From Windows‑1252 From UTF‑8 space %20 %20 ! %21 %21 " %22 %22
Read more >
Space in URL getting replaced by %20 - MSDN - Microsoft
Hi,. I am creating dyanamic hyperlinks in my application. E.g. ... and this link is getting replaced when shown on IE. ... I...
Read more >
How to prevent plus sign from being replaced with space?
I have a URL that auto populates a form but every time there is a "+" as part of a text string populating...
Read more >
location.replace() - Web APIs - MDN Web Docs
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found