From 4e7d409e00291d6c83bdb1d471a1a28414053d0d Mon Sep 17 00:00:00 2001 From: Mariusz Jakubowski Date: Wed, 3 Jun 2015 14:24:25 +0200 Subject: [PATCH] do not convert arguments to File objects before checking for http prefix. Fixes #99. Signed-off-by: Mariusz Jakubowski --- .../client/SimpleCommandLineValidator.java | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/nu/validator/client/SimpleCommandLineValidator.java b/src/nu/validator/client/SimpleCommandLineValidator.java index 19699b846..242dce8a2 100644 --- a/src/nu/validator/client/SimpleCommandLineValidator.java +++ b/src/nu/validator/client/SimpleCommandLineValidator.java @@ -27,8 +27,6 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import nu.validator.htmlparser.sax.XmlSerializer; import nu.validator.messages.GnuMessageEmitter; @@ -177,13 +175,9 @@ public static void main(String[] args) throws SAXException, Exception { validator.checkHtmlInputSource(is); end(); } else if (hasFileArgs) { - List files = new ArrayList(); - for (int i = fileArgsStart; i < args.length; i++) { - files.add(new File(args[i])); - } validator = new SimpleDocumentValidator(); setup(schemaUrl); - checkFiles(files); + checkFiles(args, fileArgsStart); end(); } else { System.err.printf("\nError: No documents specified.\n"); @@ -222,13 +216,23 @@ private static void end() throws SAXException { } } - private static void checkFiles(List files) throws SAXException, - IOException { - for (File file : files) { - if (file.isDirectory()) { - recurseDirectory(file); + private static void checkFiles(String[] args, int fileArgsStart) throws IOException, SAXException { + for (int i = fileArgsStart; i < args.length; i++) { + if (args[i].startsWith("http://") || args[i].startsWith("https://")) { + emitFilename(args[i]); + try { + validator.checkHttpURL(new URL(args[i])); + } catch (IOException e) { + errorHandler.error(new SAXParseException(e.toString(), + null, args[i], -1, -1)); + } } else { - checkHtmlFile(file); + File file = new File(args[i]); + if (file.isDirectory()) { + recurseDirectory(file); + } else { + checkHtmlFile(file); + } } } } @@ -251,25 +255,7 @@ private static void recurseDirectory(File directory) throws SAXException, private static void checkHtmlFile(File file) throws IOException { try { String path = file.getPath(); - if (path.matches("^http:/[^/].+$")) { - path = "http://" + path.substring(path.indexOf('/') + 1); - emitFilename(path); - try { - validator.checkHttpURL(new URL(path)); - } catch (IOException e) { - errorHandler.error(new SAXParseException(e.toString(), - null, path, -1, -1)); - } - } else if (path.matches("^https:/[^/].+$")) { - path = "https://" + path.substring(path.indexOf('/') + 1); - emitFilename(path); - try { - validator.checkHttpURL(new URL(path)); - } catch (IOException e) { - errorHandler.error(new SAXParseException(e.toString(), - null, path, -1, -1)); - } - } else if (!file.exists()) { + if (!file.exists()) { if (verbose) { errorHandler.warning(new SAXParseException( "File not found.", null,