The replace filter calls Data.Text.replace, which raises error "Data.Text.replace: empty input" when the search string is empty. Jinja2's replace is total, so a template that passes an empty search argument renders in Jinja2 and aborts in ginger.
Reproduction
Jinja2 renders x. ginger aborts:
runtime: Data.Text.replace: empty input
CallStack (from HasCallStack):
error, called at libraries/text/src/Data/Text.hs:2108:18 in text-2.1.3-inplace:Data.Text
The same abort occurs when the search argument is missing or evaluates to the empty string.
Root cause
src/Text/Ginger/Run/Builtins.hs:327-342 (gfnReplace) calls the partial Data.Text.replace with search = asText searchG; a missing argument is defaulted to an empty value.
The
replacefilter callsData.Text.replace, which raiseserror "Data.Text.replace: empty input"when the search string is empty. Jinja2'sreplaceis total, so a template that passes an empty search argument renders in Jinja2 and aborts in ginger.Reproduction
{{ ''|replace('','x') }}Jinja2 renders
x. ginger aborts:The same abort occurs when the search argument is missing or evaluates to the empty string.
Root cause
src/Text/Ginger/Run/Builtins.hs:327-342(gfnReplace) calls the partialData.Text.replacewithsearch = asText searchG; a missing argument is defaulted to an empty value.