Skip to content

replace filter aborts rendering when the search string is empty #85

Description

@Nuhiat-Arefin

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

{{ ''|replace('','x') }}

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions