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

Pattern CPT: Add basic content validation when saving a pattern #38

Merged
merged 4 commits into from
Feb 11, 2021

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Feb 3, 2021

See #22 — this PR addresses some easily-automated validation of the pattern content. I'm validating at the API level, since someone could theoretically handcraft an API request to /wp-json/wp/v2/wporg-pattern/.

✅ The REST API's default validation will prevent any invalid JSON content.
✅ Initial validation checks that there is content, and that the content is parsed as valid blocks.
✅ Content will pass the validation if there is at least one block with non-default content.

⚠️ Does it contain JS or inline CSS?
These should be stripped out by wp_kses for users, but we'll want to check that when we figure out permissions in general, #30

⚠️ Is the markup minimally valid?
I'm not sure if we need to check for this - on the frontend, any content generated by the editor should be valid. But in PHP, GB's parser is very forgiving. So "invalid" code, ex: <pThis is content, passes as a valid paragraph via the API. When that's rendered in the frontend, it triggers the invalid content warning, so anyone looking at the block would know it's broken. Checking for this would probably require something like the block directory e2e tests.

⚠️ Does it use permitted blocks? (Core only, or an allow/deny list?)
It will only pass blocks that are currently registered, so we could unregister blocks we don't want people to use (see #35).

To test

  1. Run the tests: yarn test:php

or, to manually test (in wp-admin, there's no error handling on the frontend yet)

  1. Add a pattern /wp-admin/post-new.php?post_type=wporg-pattern
  2. Save the empty content
  3. You should see an error message
  4. Add some more empty blocks, make sure not to edit any
  5. Save again, another error message
  6. Add some real content
  7. Save again, it should succeed this time

@ryelle ryelle added the [Component] Pattern Directory The backend of the pattern directory: submission, management, etc label Feb 3, 2021
@ryelle ryelle self-assigned this Feb 3, 2021
@ryelle ryelle force-pushed the add/basic-pattern-validation branch 2 times, most recently from db8305c to 6cd7e38 Compare February 4, 2021 00:07
@ryelle ryelle mentioned this pull request Feb 4, 2021
@ryelle ryelle force-pushed the add/basic-pattern-validation branch from b58f187 to acfc5e0 Compare February 4, 2021 21:34
@ryelle ryelle force-pushed the add/basic-pattern-validation branch from acfc5e0 to 2911bc5 Compare February 5, 2021 21:54
@ryelle ryelle requested a review from tellyworth February 8, 2021 17:49
@ryelle ryelle force-pushed the add/basic-pattern-validation branch from 2911bc5 to 2e0b872 Compare February 11, 2021 16:37
@ryelle ryelle merged commit fdd30b2 into trunk Feb 11, 2021
@ryelle ryelle deleted the add/basic-pattern-validation branch February 11, 2021 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Pattern Directory The backend of the pattern directory: submission, management, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant