Skip to content

Commit

Permalink
Merge pull request #1833 from adamretter/hotfix/inspect-functions
Browse files Browse the repository at this point in the history
[bugfix] Make sure to use the correct source for the URI
  • Loading branch information
wolfgangmm authored Apr 16, 2018
2 parents b85092f + 1d299d0 commit 55b8172
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/org/exist/source/SourceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ else if (location.startsWith("file:/") || !location.contains(":/")) {
}
}

if (source == null) {
if (source == null && contextPath != null) {
try {
final Path p3 = Paths.get(contextPath).toAbsolutePath().resolve(location);
if (Files.isReadable(p3)) {
Expand Down
23 changes: 15 additions & 8 deletions src/org/exist/xquery/functions/inspect/ModuleFunctions.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.exist.xquery.functions.inspect;

import org.exist.dom.QName;
import org.exist.security.PermissionDeniedException;
import org.exist.source.FileSource;
import org.exist.source.Source;
import org.exist.source.SourceFactory;
import org.exist.xquery.*;
import org.exist.xquery.Module;
import org.exist.xquery.functions.fn.FunOnFunctions;
import org.exist.xquery.functions.fn.LoadXQueryModule;
import org.exist.xquery.parser.XQueryAST;
import org.exist.xquery.value.*;

import javax.xml.xpath.XPath;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -67,20 +72,22 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
if (isCalledAs("module-functions-by-uri")) {
module = tempContext.importModule(args[0].getStringValue(), null, null);
} else {
final URI locationUri = ((AnyURIValue)args[0]).toURI();
tempContext.setSource(new FileSource(Paths.get(locationUri), false));
final URI locationUri = ((AnyURIValue) args[0]).toURI();
try {
final Source source = SourceFactory.getSource(context.getBroker(), null, locationUri.toString(), false);
tempContext.setSource(source);
} catch (final IllegalArgumentException e) {
throw new XPathException(this, e.getMessage());
}
module = tempContext.importModule(null, null, args[0].getStringValue());
}

} catch (final IOException | PermissionDeniedException e) {
throw new XPathException(this, e.getMessage());
} catch (final XPathException e) {
LOG.debug("Failed to import module: " + args[0].getStringValue() + ": " + e.getMessage(), e);

LOG.error("Failed to import module: " + args[0].getStringValue() + ": " + e.getMessage(), e);
if (e.getErrorCode().equals(ErrorCodes.XPST0003)) {
throw new XPathException(this, e.getMessage());
}

} catch (final Exception e) {
LOG.debug("Failed to import module: " + args[0].getStringValue() + ": " + e.getMessage(), e);
}

if (module == null) {
Expand Down

0 comments on commit 55b8172

Please sign in to comment.