Apache Common UrlValidator does not support unicode. alernative is avaliable?

前端 未结 2 726
广开言路
广开言路 2021-01-15 12:53

i try to url validation. but UrlValidator is does not support unicode. here is code

public static boolean isValidHttpUrl(String url) {
    String[] schemes =         


        
相关标签:
2条回答
  • 2021-01-15 12:58

    It doesn't support IDN. You need to convert URL to Punycode first. Try this,

      isValid = isValidHttpUrl(IDN.toASCII(url));
    
    0 讨论(0)
  • 2021-01-15 13:01

    There may be a more recent RFC that supersedes this one, but technically speaking URLs do not suppor Unicode. RFC1738

    The relevant section in particular:

    No corresponding graphic US-ASCII:

    URLs are written only with the graphic printable characters of the
    US-ASCII coded character set. The octets 80-FF hexadecimal are not
    used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent
    control characters; these must be encoded.

    0 讨论(0)
提交回复
热议问题