Skip to content

nunjucks shortcodes with no parameter passes empty string to function #3788

Description

@btrem

Operating system

Ubuntu 20

Eleventy

3.0.0

Describe the bug

If you add a shortcode with no parameter to a nunjucks template, it appears that the engine adds an empty string as a parameter. In other words, {% test %}is equivalent to {% test "" %}. This is not the behavior of liquid templates, where -- it appears -- {% test %}is equivalent to {% test undefined %}.

This might be related to #372. Hard to tell, because there's not much info in the issue, but I looked at the commit that resolved it (5cd19f6), and it looks like the engine adds an empty string (cf. line 80+), apparently to resolve a nunjucks bug.

Reproduction steps

  1. Create a shortcode in an eleventy config file.
  2. Call that shortcode from a nunjucks template with no parameter.
  3. console.log the typeof the parameter.

Expected behavior

In javascript, calling a function with no parameter passes undefined. So I think liquid's behavior is correct, and nunjucks' is not. However, maybe the nunjucks bug #372 prevents consistent behavior.

Demo

https://github.com/btrem/11ty_3788

Activity

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

Metadata

Metadata

Assignees

Labels

breaking-changeThis will have to be included with a major version as it breaks backwards compatibility.bug: liteDebatable whether or not this is a bug. I mean, it’s not great but it’s not really broken either.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions