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

Lack of validation of empty array types generates incorrect markup? #1618

Closed
dabd opened this issue Oct 23, 2019 · 8 comments
Closed

Lack of validation of empty array types generates incorrect markup? #1618

dabd opened this issue Oct 23, 2019 · 8 comments
Labels
🕔 hours A well understood issue which we expect to take less than a day to resolve.

Comments

@dabd
Copy link

dabd commented Oct 23, 2019

This is an issue I have found in a few components that have array parameters.

This example illustrates it.

{% if params.navigation %}
    <button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide Top Level Navigation">Menu</button>
    <nav>
...

When the array is empty params.navigation is still a truthy value so it will create the button but no navigation. If this is not the intended outcome, should a guard be added to check for an empty array?

@NickColley
Copy link
Contributor

Hello @dabd!

I believe we could do something like:

{% if params.navigation && (params.navigation | length) %}

in Nunjucks to check that there an array is not empty but I would need to double check this.

Is this something that you've run into in development or just an observation based on looking at the code, this will help us prioritise this.

@NickColley NickColley added the awaiting triage Needs triaging by team label Oct 23, 2019
@dabd
Copy link
Author

dabd commented Oct 23, 2019

Hi @NickColley, thanks for the quick reply!

This is something that I've found out by running tests on an implementation of the library's components we're working on. Our tests are checking for parity of the generated markup, and for some test cases we were getting different results because we are checking for empty arrays.

This creates a bit of a dilemma between having a faithful implementation or doing validations based on assumptions that might be incorrect. It would be nice to have these checks if that is the correct thing to do. Thanks!

@NickColley
Copy link
Contributor

NickColley commented Oct 23, 2019

Thank you for the extra context! I've added the awaiting-triage label this means we'll meet as a team next Wednesday and discuss what we want to do next.

@edwardhorsford
Copy link
Contributor

This seems sensible to me. We recently added support for not outputting markup where something wasn't provided - this feels like a natural extension.

@NickColley NickColley added 🕔 hours A well understood issue which we expect to take less than a day to resolve. Priority: low and removed awaiting triage Needs triaging by team labels Oct 30, 2019
@NickColley
Copy link
Contributor

@dabd we talked about this is a team.

Is this blocking you from completing your implementation? Is there a way you can set up your test suite to avoid sending boolean true values do your templates, is this a Scala nuance?

If it is we can look into this, if you're interested in doing a pull request for this functionality let me know too.

@dabd
Copy link
Author

dabd commented Oct 30, 2019 via email

@silasl
Copy link

silasl commented Nov 12, 2019

A PR has been raised for this: #1638

@hannalaakso
Copy link
Member

@dabd I believe that #1638 has fixed this so closing the issue but you can re-open if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕔 hours A well understood issue which we expect to take less than a day to resolve.
Projects
Development

No branches or pull requests

5 participants