Skip to content

Commit

Permalink
do not convert arguments to File objects before checking for http
Browse files Browse the repository at this point in the history
prefix. Fixes validator#99.

Signed-off-by: Mariusz Jakubowski <mariusz.jakubowski.79@gmail.com>
  • Loading branch information
mariusj committed Jun 3, 2015
1 parent c619b7e commit 4e7d409
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions src/nu/validator/client/SimpleCommandLineValidator.java
Expand Up @@ -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;
Expand Down Expand Up @@ -177,13 +175,9 @@ public static void main(String[] args) throws SAXException, Exception {
validator.checkHtmlInputSource(is);
end();
} else if (hasFileArgs) {
List<File> files = new ArrayList<File>();
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");
Expand Down Expand Up @@ -222,13 +216,23 @@ private static void end() throws SAXException {
}
}

private static void checkFiles(List<File> 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);
}
}
}
}
Expand All @@ -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,
Expand Down

0 comments on commit 4e7d409

Please sign in to comment.