最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - problems with decodeURI with %^ characters - Stack Overflow

programmeradmin1浏览0评论

Code:

<script type="text/javascript">  
  var uri = "%^my test**.asp?name=ståle&car=saab";
  document.write(decodeURI(uri));   
</script>

Error:

Line: 6
Error: The URI to be decoded is not a valid encoding

Is there anyway of decoding the binations like %^ before calling the actual decodeURI?

Code:

<script type="text/javascript">  
  var uri = "%^my test**.asp?name=ståle&car=saab";
  document.write(decodeURI(uri));   
</script>

Error:

Line: 6
Error: The URI to be decoded is not a valid encoding

Is there anyway of decoding the binations like %^ before calling the actual decodeURI?

Share Improve this question edited Dec 31, 2019 at 20:19 Jeff Mergler 1,54422 silver badges30 bronze badges asked Nov 26, 2009 at 7:25 balalakshmibalalakshmi 4,2366 gold badges42 silver badges48 bronze badges 3
  • 2 are you sure you dont mean to "encode" rather than decode? – Ayyash Commented Nov 26, 2009 at 7:31
  • 1 Why is that %^ in the URI anyway, and what do you want it to be decoded to? – Carl Smotricz Commented Nov 26, 2009 at 7:32
  • 1 Agreed, at least why is % there, because it is the escape character for encoding other URI entities. Plus you have other non ASCII characters in the URI, which should be encoded, as it isn't safe to assume Unicode characters can be handled in URIs – Kitson Commented Nov 26, 2009 at 8:18
Add a ment  | 

1 Answer 1

Reset to default 4

That is not a valid URI. URIs aren't allowed to contain unencoded non-ASCII or reserved characters. You can't use literal %, it has to be encoded as %25.

 var uri="%25^my%20test.asp?name=st%C3%A5le&car=saab";
发布评论

评论列表(0)

  1. 暂无评论