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

Gallery block: Strip HTML from caption before using as alt attribute. #26549

Closed
ockham opened this issue Oct 28, 2020 · 3 comments · Fixed by #26676
Closed

Gallery block: Strip HTML from caption before using as alt attribute. #26549

ockham opened this issue Oct 28, 2020 · 3 comments · Fixed by #26676
Assignees
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@ockham
Copy link
Contributor

ockham commented Oct 28, 2020

Describe the bug
Per #26082, in the gallery block, for an image without an alt text specified, we're using the image's caption as a fallback. However, the caption can contain HTML (e.g. a link, i.e. an <a /> tag) that we should strip from it when using it as alt text.

To reproduce
Steps to reproduce the behavior:

  1. Insert a gallery block.
  2. Add a few images.
  3. Add a caption to one of the images.
  4. Highlight part of the caption and add a link (e.g. to wordpress.org).
  5. Publish the post, and view it one the frontend.
  6. Inspect the page source.
  7. Verify that the image's alt attribute includes the HTML (<a /> element).

Expected behavior
HTML should be removed from the caption when used as alt attribute.

Screenshots
N/A

Editor version (please complete the following information):

  • WordPress version: 5.5
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? Gutenberg plugin v9.2.2 installed.
  • If the Gutenberg plugin is installed, which version is it? [e.g., 7.6]

Brought up here. When used with other plugins, there can be issued with incorrectly mangled HTML in attributes, see e.g. Automattic/wp-calypso#46813.

cc/ @ZebulanStanphill

@ockham ockham added [Type] Task Issues or PRs that have been broken down into an individual action to take [Block] Gallery Affects the Gallery Block - used to display groups of images labels Oct 28, 2020
@ockham
Copy link
Contributor Author

ockham commented Oct 28, 2020

Let's also add test coverage when providing a fix 🙂

@tellthemachines tellthemachines added [Type] Bug An existing feature does not function as intended and removed [Type] Task Issues or PRs that have been broken down into an individual action to take labels Oct 28, 2020
@ockham
Copy link
Contributor Author

ockham commented Oct 29, 2020

Aaand I guess we'll need a migration, since this will be changing the block content (as saved by save.js).

@ockham
Copy link
Contributor Author

ockham commented Oct 29, 2020

We can probably use __unstableStripHTML() from @wordpress/dom here (need to figure out why it's marked as unstable).

@WunderBart WunderBart self-assigned this Oct 29, 2020
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Oct 29, 2020
@WunderBart WunderBart removed the [Status] In Progress Tracking issues with work in progress label Oct 30, 2020
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
3 participants