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

Fix Nav block fallback DB query to match on full block grammar start tag #36854

Merged
merged 1 commit into from Nov 25, 2021

Conversation

getdave
Copy link
Contributor

@getdave getdave commented Nov 25, 2021

Description

Currently when seeking fallback Navigation Menus to use as the front-of-site fallback for the block rendering the Nav block looks for opening <!-- tags to fetch the first post that has blocks.

However this is vulnerable to error because the post might contain a non-block HTML comment which would then be treated as valid.

Whilst we are protected by the code which filters out the resulting null blocks that would be returned by the block parser we can safe guard against this in advance by searching for the full block comment <!-- wp:.

I checked and this comment is used by all blocks, even those which aren't core blocks. Here's an example using Kadence blocks:

Screen Shot 2021-11-25 at 10 23 34

How has this been tested?

  • Delete all Navigation Menu posts from your site - http://localhost:8888/wp-admin/edit.php?post_type=wp_navigation.
  • Add several Pages to your site.
  • Add a Nav block to your site. Add some items.
  • Save the Site Editor and thus the Nav Menu.
  • Reload the Site Editor.
  • Go to the Nav block and delete it. Then re-add an empty Nav block and save the Editor.
  • Now go into your database and modify the Navigation Menu post to contain an HTML comment that is not block grammar. Eg:
<!-- Some other random HTML comment -->And some stuff here!
  • Visit front of site. You should see the core/page-list block used to render the default fallback experience.
  • You should not see the Navigation used because it is invalid as blocks.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@getdave getdave self-assigned this Nov 25, 2021
@getdave getdave added [Block] Navigation Affects the Navigation Block [Type] Bug An existing feature does not function as intended Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Nov 25, 2021
@getdave getdave added this to 👀 PRs needing review in Navigation block via automation Nov 25, 2021
@adamziel adamziel merged commit f439aef into trunk Nov 25, 2021
@adamziel adamziel deleted the fix/nav-block-improve-db-query-for-nav-menus branch November 25, 2021 13:53
Navigation block automation moved this from 👀 PRs needing review to ✅ Done Nov 25, 2021
@github-actions github-actions bot added this to the Gutenberg 12.1 milestone Nov 25, 2021
@noisysocks noisysocks removed the Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants