Skip to content

Guard is escaped checks with is defined - #115

Open
colinrotherham wants to merge 7 commits into
mainfrom
guard-escaped
Open

Guard is escaped checks with is defined#115
colinrotherham wants to merge 7 commits into
mainfrom
guard-escaped

Conversation

@colinrotherham

@colinrotherham colinrotherham commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Looks like we've found an issue with Jinja's is escaped when ChainableUndefined is used

Replacing the is escaped check with is defined and … is escaped resolves the issue

Raised this with Jinja in pallets/jinja#2244

@sonarqubecloud

Copy link
Copy Markdown

@colinrotherham colinrotherham changed the title Guard necessary is escaped checks with is defined and … is escaped Guard is escaped checks with is defined Aug 27, 2026
Comment on lines +75 to +91
macro_name = component_name_to_macro_name(component_name)
macro_path = f"nhsuk/components/{component_name}/macro.jinja"
macro_string = f'{{% from "{macro_path}" import {macro_name} -%}}\n\n'
macro_call = f"{macro_name}()"

if context:
macro_call = f"{macro_name}({json.dumps(context, ensure_ascii=False)})"

# If we're nesting child components or text, pass the children to the macro
# using the 'caller' Jinja feature
macro_string += (
f"{{% call {macro_call} %}}\n{call_block.strip()}\n{{%- endcall %}}"
if call_block
else f"{{{{ {macro_call} }}}}"
)

return environment.from_string(macro_string).render().rstrip()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please excuse all the renaming

I've copied the naming convention and new-line trimming from:
https://github.com/nhsuk/nhsuk-frontend/blob/main/packages/nhsuk-frontend/src/nhsuk/lib/nunjucks/index.mjs#L44

I got close to have all tests passing without needing a formatter

One to finish off another day though

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

Successfully merging this pull request may close these issues.

1 participant