S.redirectTo with Non-ASCII Chars

69 views
Skip to first unread message

Ben Phelan

unread,
Mar 14, 2012, 11:35:26 PM3/14/12
to lif...@googlegroups.com
S.redirectTo doesn't seem to work with non-ascii characters, although I haven't been able to figure out why so far.

For example, when calling S.redirectTo("/ß") the browser is redirected to /%DF instead of /%C3%9F.  There doesn't seem to be any problem with encJs("/ß") == "/\u00df" and throwing a raw <script>window.location = "/\u00df";</script> into a template gives the desired result.  So I'm guessing my issue has something to do with URLRewriter?

Is there a setting somewhere that would resolve this or some other simple way to get this working?

Cheers,
Ben

David Pollak

unread,
Mar 15, 2012, 3:44:50 AM3/15/12
to lif...@googlegroups.com
On Thu, Mar 15, 2012 at 3:35 AM, Ben Phelan <bem...@gmail.com> wrote:
S.redirectTo doesn't seem to work with non-ascii characters, although I haven't been able to figure out why so far.

For example, when calling S.redirectTo("/ß") the browser is redirected to /%DF instead of /%C3%9F.  There doesn't seem to be any problem with encJs("/ß") == "/\u00df" and throwing a raw <script>window.location = "/\u00df";</script> into a template gives the desired result.  So I'm guessing my issue has something to do with URLRewriter?

URLRewriter is used for re-writing incoming requests.  It has nothing to do with outgoing requests.

It's likely something in the container.  S.redirectTo turns into:

/**

 * 301 Redirect.

 */

case class PermRedirectResponse(uri: String, request: Req, cookies: HTTPCookie*) extends LiftResponse {

  def toResponse = InMemoryResponse(Array(), List("Location" -> uri), cookies.toList, 301)

}


/**

 * 307 Redirect.

 */

case class TemporaryRedirectResponse(uri: String, request: Req, cookies: HTTPCookie*) extends LiftResponse {

  def toResponse = InMemoryResponse(Array(), List("Location" -> uri), cookies.toList, 307)

}


The only thing going on here is setting the Location header to the uri.  I'm betting the location header conversion stuff is not done with the correct character encoding by whatever containers you're using.  For kicks, try adding a header "X-FooBar" with the value "/ß" and see what comes out the other side.

 

Is there a setting somewhere that would resolve this or some other simple way to get this working?

Cheers,
Ben

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Ben Phelan

unread,
Mar 15, 2012, 11:16:39 AM3/15/12
to lif...@googlegroups.com
Thanks David!  My 3am code-tracing skills obviously need some work. :)

I can't find anything anywhere about fixing the issue at the container level with Jetty 6, 7 or 8.  The simplest solution seems to be to just S.redirectTo("/' + URLEncoder.encode("non-ascii string", "UTF-8")).

Cheers,
Ben

David Pollak

unread,
Mar 15, 2012, 5:54:05 PM3/15/12
to lif...@googlegroups.com
On Thu, Mar 15, 2012 at 3:16 PM, Ben Phelan <bem...@gmail.com> wrote:
Thanks David!  My 3am code-tracing skills obviously need some work. :)

Asking questions like yours is what this list is here for.
 
I can't find anything anywhere about fixing the issue at the container level with Jetty 6, 7 or 8.  The simplest solution seems to be to just S.redirectTo("/' + URLEncoder.encode("non-ascii string", "UTF-8")).

That's really ugly.  Can you open a ticket on this issue?  I'll put the conversion to UTF-8 in the header stuffing code.
 

Cheers,
Ben

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Ben Phelan

unread,
Mar 18, 2012, 5:03:33 PM3/18/12
to lif...@googlegroups.com
Ok, will post a ticket (to github, one assumes) when I get a minute.

Thanks David.

Ben Phelan

unread,
Mar 21, 2012, 11:10:28 AM3/21/12
to lif...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages