Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix: Pasting captions without an image fails #14365
Conversation
dmsnell
requested a review
from
ellatrix
Mar 10, 2019
dmsnell
requested review from
ajitbohra,
gziolo,
jorgefilipecosta,
noisysocks,
notnownikki,
Soean,
talldan and
youknowriad
as
code owners
Mar 10, 2019
dmsnell
force-pushed the
fix/13527-captions-missing-image-on-paste
branch
from
5a6ac0c
to
3518cdd
Mar 11, 2019
dmsnell
removed
the
[Status] In Progress
label
Mar 11, 2019
youknowriad
referenced this pull request
Mar 11, 2019
Closed
Avoid JS error when pasing a caption without image #13557
gziolo
added this to the 5.3 (Gutenberg) milestone
Mar 11, 2019
gziolo
added
the
Good First Review
label
Mar 11, 2019
gziolo
approved these changes
Mar 11, 2019
Awesome teamwork Lannister! Thanks for fixing it with the unit test included. I'd love to see more PRs like this in the future :) |
gziolo
requested changes
Mar 11, 2019
Too soon. There is a failing unit test:
It looks like image should be removed together wit all wrapping html tags like anchor in this case. |
This comment has been minimized.
This comment has been minimized.
@gziolo this is ready for another look. I also added another unit test to account for the extra case. |
gziolo
approved these changes
Mar 18, 2019
This comment has been minimized.
This comment has been minimized.
Thanks for addressing my comment. This change fixes this newly introduced side effect of improved handling |
gziolo
merged commit cafb041
into
master
Mar 18, 2019
gziolo
deleted the
fix/13527-captions-missing-image-on-paste
branch
Mar 18, 2019
Mar 18, 2019
This was referenced
jorgefilipecosta
referenced this pull request
Mar 20, 2019
Closed
Update WordPress trunk to Gutenberg 5.3 #14532
youknowriad
added a commit
that referenced
this pull request
Mar 20, 2019
youknowriad
added a commit
that referenced
this pull request
Mar 20, 2019
mkevins
added a commit
to mkevins/gutenberg
that referenced
this pull request
Mar 26, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
dmsnell commentedMar 10, 2019
•
edited by gwwar
Fixes #13527
See original work in #12315
See reduced input that produces the problem, shortened from the original.
When pasting content which includes the
[caption]
shortcode we assumethat the content is well-formed (that there is not only an
<img />
inthere but also in the first position).
In this patch we fix the problem by removing the old code, which removed
the first
Element
node, and replaced it with code that removes thefirst
IMG
node if one is found.We're leaving other image nodes in place in case the caption contains
image nodes and we're not requiring that the
IMG
be the first childof the caption shortcode in case people are wrapping the image in other
valid HTML like this...
See the new unit tests for a more complete specification of the
intended behaviors.
PR reviewed, debugged, and created by:
-> LANNISTER MOB <-
Testing
Confirm that the new unit tests pass:
npm run test-unit packages/block-library/src/image npm run test test/integration/blocks-raw-handling.spec.js
Also test by pasting in the input text which triggers the bug. In
master
itshould fail as described with the error in the console but in this
branch it should paste as expected without error and an image block
should appear.
Finally verify that no regressions occur when converting a classic block
which contains images with the
[caption]
shortcode. This was the goalof #12315 when it was merged.