-
Notifications
You must be signed in to change notification settings - Fork 328
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
Fix attributes
option ignoring values passed from the safe
filter
#4938
Conversation
Updates the `govukAttributes` macro to look for an object that matches the shape of those returned by Nunjucks' `safe` filter. If found, the value of that object is mapped to the value that should be used by the macro.
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for fe7a019 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the speedy fix. The solution looks very fine to me, I'm not sure if we'd have access to the SafeString
class to check types anyway (and trying to check the type could lead to subtle issues, which would complicate our testing).
Thinking we can explore the forced escaping in another PR if we get feedback it causes issues.
I'll see about raising another issue specifically about using |
govukAttributes
macro not outputting values passed from the safe
filterattributes
option ignoring values passed from the safe
filter
Updates the
govukAttributes
macro to, when passed a set of key-value pairs, check if the value is an object that matches the shape of those returned by Nunjucks'safe
filter (i.e. an object withval
andlength
keys).If found, that object's
val
is used in place of the object. Previously, this would just be lost and the macro would return an empty string.If the value is an object that doesn't have those specific keys, it is instead treated as one of our attribute configuration objects (which use the keys
value
andoptional
instead).Resolves #4937.
Changes
govukAttributes
attribute loop to look for objects resembling the output of thesafe
filter. If matched, the object'sval
value is mapped to the macro's working value.safe
filter are output by the macro as expected.Thoughts
Checking for the existence of two keys is definitely not a foolproof way of ensuring that the object is actually one returned by the
safe
filter, however I'm not sure there is a more obvious way of detecting its use.This does not create output that perfectly matches the expected output in #4937, as HTML is still returned escaped even if
safe
is used by the author. This is because the macro indiscriminately escapes all of the attributes and values it outputs.