Urldecoder:illegal hex characters in Escape (%) pattern-for input string:

Source: Internet
Author: User

From: http://stackoverflow.com/questions/11257509/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string-p

Whoever created the URL should has percent encoded the by % writing %25 .

Example Invalid URL

Http://example.com/test?q=%.P

Example valid URL

Http://example.com/test?q=%25.P

The answer provided by Mark Byers would work just fine if there ' re only chars this need to being escaped but would % fail I F URL contains percent-encoded chars. To avoid the there ' s a little bit more work needed.

In Percent-encoding (url-encoding) only reserved and unreserved chars won ' t is percent-encoded.

ReservedChars:╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║ ! ║ # ║$║ & ║ ‘ ║ ( ║ ) ║ * ║ + ║ , ║ / ║ : ║ ; ║ = ║ ? ║ @ ║ [ ║ ] ║╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝UnreservedChars:╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║A║B║C║D║E║F║G║H║I║J║K║L║M║N║O║P║Q║R║╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║S║T║U║V║W║X║Y║Z║A║B║C║D║E║F║G║H║I║J║╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║K║L║M║N║O║P║Q║R║S║T║U║V║W║X║Y║Z║╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗║ 0 ║ 1 ║ 2 ║ 3 ║ 4 ║ 5 ║  6 ║ 7║ 8 ║  9 ║  - ║ _ ║ ║ ~  ║╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝     

According to RFC 3986 percent-encoded character have following format: % + hex . So if you want to properly escape URLs that have unescaped % chars without breaking the whole URL before actually Decodi Ng it, you need to replace only those signs that is not % followed by Hex.

Finding substring that violates some the pattern is pretty easy task with regex. In this case pattern would look like this:

%(?![0-9a-fA-F]{2})

Sample:

Class Main{ Public Static voidMain(String[]Args) ThrowsJava.Lang.Exception { string URL = ; URL = Urlreplaceall ( "% (?! [0-9a-fa-f] {2}) " , ); system.. Printlnurl}}          /span>                

Urldecoder:illegal hex characters in Escape (%) pattern-for input string:

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.