Comments (12)
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.
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.
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.
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:
- Decode anything but reserved characters
- Match routes
- 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.
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
- Don't decode during routing
- Match routes
- Decode params
from scalatra.
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.
For reference, the most recent thread on the subject.
from scalatra.
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.
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.
We have a URL en/decoder that does all that stuff: https://github.com/mojolly/rl
from scalatra.
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.
Result of the IRC conversation, before we forget and start arguing for another year:
- Start with
request.getRequestURI
. - Decode the path except
[?/#]
- Remove context path.
- For servlets only, remove the servlet path.
- Match the route.
- Decode the extracted route params (takes care of
[?/#]
).
from scalatra.
Related Issues (20)
- fileParams doesn't provide function to get the list of values HOT 5
- RichRequest.remoteAddress does not account for multiple IP addresses in X-Forwarded-For header HOT 5
- Please add support for plain standard websocket!!! HOT 4
- Deprecate Scalate HOT 5
- Issue with mongoDB example on website HOT 1
- Shouldn't we release Scalatra 2.8?
- drop support Scala 2.11
- Deprecate Atmosphere HOT 2
- Scala 3 HOT 10
- Release Scalatra 2.8.0 HOT 2
- object json4s is not a member of package org HOT 1
- Update org.apache.commons:commons-text to 1.10 for Scalatra 2.8.x HOT 1
- Consider releasing a Jakarta-based flavour of Scalatra 3.x HOT 11
- Scalatra 3.0.0-Mx artifacts contain Java 17 bytecode HOT 8
- Trying to generate classes using openapi.yaml results in compilation errors.
- Release schedule for Scalatra 3.0 HOT 9
- scalatra.org is down HOT 2
- `java.util.Locale` deprecation warnings
- Ok(404l) returns an actual 404 error code
- Release Scalatra 3.1.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalatra.