Giter Club home page Giter Club logo

Comments (12)

zentrope avatar zentrope commented on May 21, 2024

Ah, yes, I was part of that discussion. I'm interested in when this gets fixed, or if this is just a design choice for scalatra.

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

This one is hard. The corner cases we fix here are going to introduce other corner cases for non-root servlets. A workaround is to override requestPath. We can provide an example -- perhaps even a utility object. But this can be deferred post 2.0.0.

from scalatra.

mattkanwisher avatar mattkanwisher commented on May 21, 2024

Yeah I had the same issue this is what we did

override def requestPath = request.getRequestURI match {
case pathInfo: String => pathInfo
case null => "/"
}

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

If we decode too early, we lose escaped characters: /artist/:name should match URI /artist/AC%2FDC with name -> AC/DC. If we decode too late, it's hard to match diacritics. should match URI /%C3%B6.

What if we:

  1. Decode anything but reserved characters
  2. Match routes
  3. Decode params extracted from the routes

Probably a little slower than what we do today. Raises ugly corner cases in chopping off the servlet path -- does anyone have encoded characters in their servlet path? Is mojolly's URI library any use to us here? What else are we breaking?

from scalatra.

mattkanwisher avatar mattkanwisher commented on May 21, 2024

For example we have encoded redirect urls in our path abc.com/asdf/redirect/http://www.apple.com so the http:// .. is encoded, and this might be unique enough of a case that we should just override your handler, but it seems like

  1. Don't decode during routing
  2. Match routes
  3. Decode params

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

Let's say you're writing an app to manage German pedestrian crossings. (And let's say I'm a nerd and wrote an awk script to find the word with the most umlauts.) If you decode before route matching, you can do:

get("/Fußgängerübergänge/:id") { ... }

If you don't decode first, you have to write:

get("/Fu%C3%9Fg%C3%A4nger%C3%BCberg%C3%A4nge/:id") { ... }

The compromise in my previous comment should be convienent for both Matt's use case and this one. It means we have to abandon the standard library URL decoder, which is a big downside to my approach.

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

For reference, the most recent thread on the subject.

from scalatra.

mattkanwisher avatar mattkanwisher commented on May 21, 2024

Hrmm didn't realize unicode chars like umlauts needed to be encoded, talked to some German friends and it seems like a problem. That sounds like a nice compromise, not sure people tend to use utf-8 chars in urls for this reason cause it makes it alot more difficult to decide which ones to decode and which ones not. When you say reserved characters you mean like : / ? how are you going to decide that.

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

I was thinking of these reserved characters. That's the full set of characters whose meaning may vary based on being escaped. We might be able to shave that down some since we know we're dealing with HTTP, but that's at least a superset of characters that we want to leave alone.

from scalatra.

casualjim avatar casualjim commented on May 21, 2024

We have a URL en/decoder that does all that stuff: https://github.com/mojolly/rl

from scalatra.

casualjim avatar casualjim commented on May 21, 2024

Sorry here: https://github.com/mojolly/rl/blob/next/src/main/scala/rl/UrlCodingUtils.scala

As a bonus it's faster than the java version too

from scalatra.

rossabaker avatar rossabaker commented on May 21, 2024

Result of the IRC conversation, before we forget and start arguing for another year:

  1. Start with request.getRequestURI.
  2. Decode the path except [?/#]
  3. Remove context path.
  4. For servlets only, remove the servlet path.
  5. Match the route.
  6. Decode the extracted route params (takes care of [?/#]).

from scalatra.

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.