Changeset 1084:654bdc23be93

Show
Ignore:
Timestamp:
05/18/10 11:13:37 (3 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@1085
Message:

fixed uri syntax check

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/org/w3c/unicorn/input/URIInputParameter.java

    r1027 r1084  
    6666                                throw new UnicornException(); 
    6767                         
    68                         Pattern urlPattern = Pattern.compile("^(https?)://([A-Z0-9][A-Z0-9_-]*)(\\.[A-Z0-9][A-Z0-9_-]*)*(:(\\d+))?([/#]\\p{ASCII}*)?", Pattern.CASE_INSENSITIVE); 
    69                         if (!urlPattern.matcher(uri).matches()) { 
    70                                 if (!uri.contains("://"))  
     68                        //Pattern urlPattern = Pattern.compile("^(https?)://([A-Z0-9][A-Z0-9_-]*)(\\.[A-Z0-9][A-Z0-9_-]*)+(:(\\d+))?([/#]\\p{ASCII}*)?", Pattern.CASE_INSENSITIVE); 
     69                        Pattern protocolPattern = Pattern.compile("^\\p{Alpha}*://.*"); 
     70                        try { 
     71                                docUrl = new URL(uri); 
     72                        } catch (MalformedURLException e) { 
     73                                if (protocolPattern.matcher(uri).matches()) 
     74                                        throw e; 
     75                                else { 
    7176                                        uri = "http://" + uri; 
    72                                 if (!urlPattern.matcher(uri).matches()) 
    73                                         throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", null, uri); 
     77                                        docUrl = new URL(uri); 
     78                                }  
    7479                        } 
    75                         docUrl = new URL(uri); 
     80                         
    7681                        if (!docUrl.getProtocol().equals("http") && !docUrl.getProtocol().equals("https")) 
    7782                                throw new UnicornException(Message.ERROR, "$message_unsupported_protocol", null, docUrl.getProtocol()); 
     
    100105                        inputModule = new URIInputModule(mimeType, uri); 
    101106                } catch (MalformedURLException e) { 
    102                         throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", null, uri); 
     107                        throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", e.getMessage(), uri); 
    103108                } catch (MimeTypeParseException e) { 
    104109                        throw new UnicornException(Message.ERROR, "$message_invalid_mime_type");