Skip to content

Commit 96c838f

Browse files
authored
Merge pull request #34 from joewiz/fix/resolve-infinite-loop
Prevent infinite loop in function lookup
2 parents d9d2c8e + 1af951a commit 96c838f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

content/templates.xql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ xquery version "3.1";
55
:
66
: @version 2.1
77
: @author Wolfgang Meier
8-
: @contributor Adam retter
8+
: @contributor Adam Retter
9+
: @contributor Joe Wicentowski
910
:)
1011
module namespace templates="http://exist-db.org/xquery/templates";
1112

@@ -30,6 +31,7 @@ declare variable $templates:NOT_FOUND := QName("http://exist-db.org/xquery/templ
3031
declare variable $templates:TOO_MANY_ARGS := QName("http://exist-db.org/xquery/templates", "TooManyArguments");
3132
declare variable $templates:PROCESSING_ERROR := QName("http://exist-db.org/xquery/templates", "ProcessingError");
3233
declare variable $templates:TYPE_ERROR := QName("http://exist-db.org/xquery/templates", "TypeError");
34+
declare variable $templates:MAX_ARITY := 20;
3335

3436
declare variable $templates:ATTR_DATA_TEMPLATE := "data-template";
3537

@@ -187,7 +189,11 @@ declare %private function templates:call($classOrAttr as item(), $node as elemen
187189
if (exists($call)) then
188190
templates:call-by-introspection($node, $parameters, $model, $call)
189191
else if ($model($templates:CONFIGURATION)($templates:CONFIG_STOP_ON_ERROR)) then
190-
error($templates:NOT_FOUND, "No template function found for call " || $func)
192+
error($templates:NOT_FOUND,
193+
"No template function found for call " || $func ||
194+
" (Max arity of " || $templates:MAX_ARITY ||
195+
" has been exceeded in searching for this template function." ||
196+
"If needed, adjust $templates:MAX_ARITY in the templates.xql module.)")
191197
else
192198
(: Templating function not found: just copy the element :)
193199
element { node-name($node) } {
@@ -294,6 +300,8 @@ declare %private function templates:resolve($arity as xs:int, $func as xs:string
294300
return
295301
if (exists($fn)) then
296302
$fn
303+
else if ($arity ge $templates:MAX_ARITY) then
304+
()
297305
else
298306
templates:resolve($arity + 1, $func, $resolver)
299307
};

0 commit comments

Comments
 (0)