Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating fails when a comment contains '#}' #1428

Open
mgarstecki opened this issue Jan 16, 2023 · 1 comment
Open

Templating fails when a comment contains '#}' #1428

mgarstecki opened this issue Jan 16, 2023 · 1 comment

Comments

@mgarstecki
Copy link

mgarstecki commented Jan 16, 2023

Hi,

I get the following error when my template contains the string #} as a comment:

  Error: unexpected end of comment
    at Object._prettifyError (/home/mat/node_modules/nunjucks/src/lib.js:36:11)
    at Template.render (/home/mat/node_modules/nunjucks/src/environment.js:538:21)
    at /home/mat/node_modules/nunjucks/src/environment.js:366:27
    at createTemplate (/home/mat/node_modules/nunjucks/src/environment.js:315:9)
    at handle (/home/mat/node_modules/nunjucks/src/environment.js:327:11)
    at /home/mat/node_modules/nunjucks/src/environment.js:339:9
    at next (/home/mat/node_modules/nunjucks/src/lib.js:328:7)
    at Object.asyncIter (/home/mat/node_modules/nunjucks/src/lib.js:334:3)
    at Environment.getTemplate (/home/mat/node_modules/nunjucks/src/environment.js:321:9)
    at Environment.render (/home/mat/node_modules/nunjucks/src/environment.js:360:10)

Minimal template that causes the issue:

#}

This is an issue because that pattern can easily be introduced when commenting blocks in the template. I encountered it when templating Terraform code, at some point my IDE commented the code in this way:

#block = {
#  test = "value"
#}

This kind of comment pattern can easily sneak-in when editing code.

I'd expect nunjucks to skip the #} token if it misses the opening one, for ease of use and to avoid being surprised: I don't expect a user of the lib to understand that this is interpreted as a end-of-comment token, especially since this tends to follow harmless comment lines.

Thanks for the hard work, available for discussion of course 🙂

@NextThread
Copy link

hey, can I work on this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants