- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 18 May 2010 11:13:39 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/input In directory hutz:/tmp/cvs-serv23202/src/org/w3c/unicorn/input Modified Files: URIInputParameter.java Log Message: fixed uri syntax check Index: URIInputParameter.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/input/URIInputParameter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- URIInputParameter.java 23 Mar 2010 11:24:24 -0000 1.17 +++ URIInputParameter.java 18 May 2010 11:13:37 -0000 1.18 @@ -65,14 +65,19 @@ if (uri.equals("referer")) throw new UnicornException(); - Pattern urlPattern = Pattern.compile("^(https?)://([A-Z0-9][A-Z0-9_-]*)(\\.[A-Z0-9][A-Z0-9_-]*)*(:(\\d+))?([/#]\\p{ASCII}*)?", Pattern.CASE_INSENSITIVE); - if (!urlPattern.matcher(uri).matches()) { - if (!uri.contains("://")) + //Pattern urlPattern = Pattern.compile("^(https?)://([A-Z0-9][A-Z0-9_-]*)(\\.[A-Z0-9][A-Z0-9_-]*)+(:(\\d+))?([/#]\\p{ASCII}*)?", Pattern.CASE_INSENSITIVE); + Pattern protocolPattern = Pattern.compile("^\\p{Alpha}*://.*"); + try { + docUrl = new URL(uri); + } catch (MalformedURLException e) { + if (protocolPattern.matcher(uri).matches()) + throw e; + else { uri = "http://" + uri; - if (!urlPattern.matcher(uri).matches()) - throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", null, uri); + docUrl = new URL(uri); + } } - docUrl = new URL(uri); + if (!docUrl.getProtocol().equals("http") && !docUrl.getProtocol().equals("https")) throw new UnicornException(Message.ERROR, "$message_unsupported_protocol", null, docUrl.getProtocol()); @@ -99,7 +104,7 @@ mimeType = new MimeType(sMimeType); inputModule = new URIInputModule(mimeType, uri); } catch (MalformedURLException e) { - throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", null, uri); + throw new UnicornException(Message.ERROR, "$message_invalid_url_syntax", e.getMessage(), uri); } catch (MimeTypeParseException e) { throw new UnicornException(Message.ERROR, "$message_invalid_mime_type"); } catch (UnknownHostException e) {
Received on Tuesday, 18 May 2010 11:13:41 UTC