Skip to content

Commit

Permalink
Fix for issue#495. Adds a check whether current dir + path is absolut…
Browse files Browse the repository at this point in the history
…e path or not.
  • Loading branch information
yokolet committed Feb 23, 2012
1 parent 32a851c commit ef406cc
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions ext/java/nokogiri/internals/ParserContext.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* (The MIT License)
*
* Copyright (c) 2008 - 2011:
* Copyright (c) 2008 - 2012:
*
* * {Aaron Patterson}[http://tenderlovemaking.com]
* * {Mike Dalessio}[http://mike.daless.io]
Expand Down Expand Up @@ -115,13 +115,18 @@ public void setInputSource(ThreadContext context, IRubyObject data, IRubyObject
}

if (isAbsolutePath(path)) {
source = new InputSource();
if (detected_encoding != null) {
source.setEncoding((String) detected_encoding.toJava(String.class));
}
source.setSystemId(path);
returnWithSystemId(path);
return;
}
// Dir.chdir might be called at some point before this.
String currentDir = context.getRuntime().getCurrentDirectory();
if (path != null && currentDir != null && currentDir.length() != 0) {
String absPath = currentDir + "/" + path;
if (isAbsolutePath(absPath)) {
returnWithSystemId(absPath);
return;
}
}
RubyString stringData = null;
if (invoke(context, data, "respond_to?",
ruby.newSymbol("to_io").to_sym()).isTrue()) {
Expand Down Expand Up @@ -164,6 +169,15 @@ private boolean isAbsolutePath(String url) {
if (url == null) return false;
return (new File(url)).isAbsolute();
}

private void returnWithSystemId(String url) {
source = new InputSource();
if (detected_encoding != null) {
source.setEncoding((String) detected_encoding.toJava(String.class));
}
source.setSystemId(url);
return;
}

/**
* Set the InputSource to read from <code>file</code>, a String filename.
Expand Down

0 comments on commit ef406cc

Please sign in to comment.