Changeset 1084:654bdc23be93
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1027
|
r1084
|
|
| 66 | 66 | throw new UnicornException(); |
| 67 | 67 | |
| 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 { |
| 71 | 76 | 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 | } |
| 74 | 79 | } |
| 75 | | docUrl = new URL(uri); |
| | 80 | |
| 76 | 81 | if (!docUrl.getProtocol().equals("http") && !docUrl.getProtocol().equals("https")) |
| 77 | 82 | throw new UnicornException(Message.ERROR, "$message_unsupported_protocol", null, docUrl.getProtocol()); |
| … |
… |
|
| 100 | 105 | inputModule = new URIInputModule(mimeType, uri); |
| 101 | 106 | } 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); |
| 103 | 108 | } catch (MimeTypeParseException e) { |
| 104 | 109 | throw new UnicornException(Message.ERROR, "$message_invalid_mime_type"); |