Injecting UrlEncoded string into page - Firefox vs Chrome
It seems the following markup is rendered differently in Firefox and Chrome, an开发者_Python百科d I'm not sure how to prevent it:
<%= HttpUtility.UrlEncode("+") %>
<%= "<a href='#' name='" + HttpUtility.UrlEncode("+") + "'>stuff</a>"%>
In Firefox it looks like:
%2b<a name="+" href="#">stuff</a>
%2b<a name="%2b" href="#">stuff</a>
Is there a way around it?
This is just a difference in the way Firebug and the Chrome developer tools display the name. If you view the source you'll find %2b
in both, and that's what it'll be if you're referring to it in script (or in a link such as <a href="#%2b">
).
I got around this issue by manually checking in code behind whether returned string contained '+' or '=' and UrlEncoded appropriately. While this is not a great solution, it was acceptable in my case since I know decoded string contained both '+' and '=', so I could infer whether it was encoded depending on whether they were present.
精彩评论