开发者

Safari encodes already encoded URL on request

开发者 https://www.devze.com 2023-01-06 06:46 出处:网络
I do an HTTP GET request for a page using the following URL in Saf开发者_StackOverflow社区ari: mysite.com/page.aspx?param=v%e5r

I do an HTTP GET request for a page using the following URL in Saf开发者_StackOverflow社区ari:

mysite.com/page.aspx?param=v%e5r

The page contains a form which posts back to itself. The HTML form tag looks like this when output by asp.net:

<form method="post" action="page.aspx?param=v%u00e5r" id="aspnetForm" >

When Safari POSTs this back it somehow converts this URL to:

page.aspx?param=v%25u00e5r, i.e. it URL encodes the already URL encoded string, which is then double encoded and the output generated by this parameter is garbled (v&#229;r). I am able to get around this some places by URL decoding the parameter before printing it.

Firefox and even IE8 handles this fine. Is this a bug in WebKit or am I doing something wrong?

To summarise:

  • GET mysite.com/page.aspx?param=v%e5r

    HTML: <form method="post" action="page.aspx?param=v%u00e5r" id="aspnetForm" >

  • POST mysite.com/page.aspx?param=v%25u00e5r

    HTML: <form method="post" action="page.aspx?param=v%25u00e5r" id="aspnetForm" >


  • mysite.com/page.aspx?param=v%e5r
    

    Whilst you can use encodings other than UTF-8 in the query part of a URL, it's inadvisable and will generally confuse a variety of scripts that assume UTF-8.

    You really want to be producing forms in pages marked as being UTF-8, then accepting UTF-8 in your application and encoding the string vår (assuming that's what you mean) as param=v%C3%A5r.

    page.aspx?param=v%u00e5r
    

    Oh dear! That's very much wrong. %uXXXX is a JavaScript-escape()-style sequence only; it is wholly invalid to put in a URL. Safari is presumably trying to fix up the mistake by encoding the % that isn't followed by a two-digit hex sequence with a %25.

    Is ASP.NET generating this? If so, that's highly disappointing. How are you creating the <form> tag? If you're encoding the parameter manually, maybe you need to specify an Encoding argument to HttpUtility.UrlEncode? ie. an Encoding.UTF8, or, if you really must have v%e5r, new Encoding(1252) (Windows code page 1252, Western European).

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消