-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bugfix] Cyclic dependency import detection for XQuery 1.0 (i.e. XQST…
…0093)
- Loading branch information
1 parent
e047354
commit e226566
Showing
3 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,10 @@ | |
|
||
|
||
/** | ||
* Subclass of {@link org.exist.xquery.XQueryContext} for | ||
* imported modules. | ||
* Subclass of {@link org.exist.xquery.XQueryContext} for imported modules. | ||
* | ||
* @author wolf | ||
* @author <a href="mailto:[email protected]">Adam Retter</a> | ||
*/ | ||
public class ModuleContext extends XQueryContext { | ||
|
||
|
@@ -66,7 +66,8 @@ public ModuleContext(final XQueryContext parentContext, final String moduleNames | |
super(parentContext != null ? parentContext.db : null, | ||
parentContext != null ? parentContext.getConfiguration() : null, | ||
null, | ||
false); | ||
false, | ||
null); | ||
this.moduleNamespace = moduleNamespace; | ||
this.modulePrefix = modulePrefix; | ||
this.location = location; | ||
|
@@ -95,6 +96,52 @@ public void setModuleNamespace(final String prefix, final String namespaceURI) { | |
this.moduleNamespace = namespaceURI; | ||
} | ||
|
||
@Override | ||
protected void addModuleVertex(final ModuleVertex moduleVertex) { | ||
getRootContext().addModuleVertex(moduleVertex); | ||
} | ||
|
||
protected boolean hasModuleVertex(final ModuleVertex moduleVertex) { | ||
return getRootContext().hasModuleVertex(moduleVertex); | ||
} | ||
|
||
@Override | ||
protected void addModuleEdge(final ModuleVertex source, final ModuleVertex sink) { | ||
getRootContext().addModuleEdge(source, sink); | ||
} | ||
|
||
@Override | ||
protected boolean hasModulePath(final ModuleVertex source, final ModuleVertex sink) { | ||
return getRootContext().hasModulePath(source, sink); | ||
} | ||
|
||
@Override | ||
public @Nullable Module[] importModule(@Nullable String namespaceURI, @Nullable String prefix, @Nullable AnyURIValue[] locationHints) throws XPathException { | ||
final ModuleVertex thisModuleVertex = new ModuleVertex(moduleNamespace, location); | ||
|
||
for (final AnyURIValue locationHint : locationHints) { | ||
final ModuleVertex imporedModuleVertex = new ModuleVertex(namespaceURI, locationHint.toString()); | ||
|
||
if (!hasModuleVertex(imporedModuleVertex)) { | ||
addModuleVertex(imporedModuleVertex); | ||
} else { | ||
// Check if there is already a path from the imported module to this module | ||
if (getXQueryVersion() == 10 && namespaceURI != null && locationHints != null && hasModulePath(imporedModuleVertex, thisModuleVertex)) { | ||
throw new XPathException(ErrorCodes.XQST0093, "Detected cyclic import between modules: " + getModuleNamespace() + " at: " + getLocation() + ", and: " + namespaceURI + " at: " + locationHint.toString()); | ||
} | ||
} | ||
|
||
if (!hasModuleVertex(thisModuleVertex)) { | ||
// NOTE(AR) may occur when the actual module has a different namespace from that of the `import module namespace`... will later raise an XQST0047 error | ||
addModuleVertex(thisModuleVertex); | ||
} | ||
|
||
addModuleEdge(thisModuleVertex, imporedModuleVertex); | ||
} | ||
|
||
return super.importModule(namespaceURI, prefix, locationHints); | ||
} | ||
|
||
@Override | ||
protected @Nullable Module importModuleFromLocation(final String namespaceURI, @Nullable final String prefix, final AnyURIValue locationHint) throws XPathException { | ||
// guard against self-recursive import - see: https://github.com/eXist-db/exist/issues/3448 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters