-
Notifications
You must be signed in to change notification settings - Fork 58
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
Validation problem on Gallery related to link settings #1659
Comments
I was able to reproduce this using a premium site. Steps I took:
The result after dismissing the validation red screen is that the gallery 1 and 3 are displayed, while gallery 2 ("Link To" = "Media File") shows "Problem displaying block".The html is different for all three galleries. I after adjusting for whitespace within the html, the differences seem to be the omission of the attribute diff --git a/valid-gallery-html2 b/invalid-gallery-html2
index e40bad6..a996b78 100644
--- a/valid-gallery-html2
+++ b/invalid-gallery-html2
@@ -3,7 +3,7 @@
<ul class="blocks-gallery-grid">
<li class="blocks-gallery-item">
<figure>
-<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" data-full-url="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg" class="wp-image-13"/>
+<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" class="wp-image-13"/>
</figure>
</li>
</ul>
@@ -16,7 +16,7 @@
<li class="blocks-gallery-item">
<figure>
<a href="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg">
-<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" data-full-url="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg" class="wp-image-13"/>
+<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" class="wp-image-13" />
</a>
</figure>
</li>
@@ -29,7 +29,7 @@
<ul class="blocks-gallery-grid">
<li class="blocks-gallery-item">
<figure>
-<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" data-full-url="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg" class="wp-image-13"/>
+<img src="https://mattspremiumtestsitetravel.files.wordpress.com/2019/12/mountaindawn.jpg?w=750" alt="" data-id="13" class="wp-image-13"/>
</figure>
</li>
</ul> |
Investigating this further, I have reproduced this on a free site as well: HTML diffdiff --git a/free-site-valid-html b/free-site-invalid-html
index 554c655..47b73dc 100644
--- a/free-site-valid-html
+++ b/free-site-invalid-html
@@ -3,7 +3,7 @@
<ul class="blocks-gallery-grid">
<li class="blocks-gallery-item">
<figure>
-<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" data-full-url="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg" class="wp-image-243"/>
+<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" class="wp-image-243"/>
</figure>
</li>
</ul>
@@ -16,7 +16,7 @@
<li class="blocks-gallery-item">
<figure>
<a href="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg">
-<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" data-full-url="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg" class="wp-image-243"/>
+<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" class="wp-image-243" />
</a>
</figure>
</li>
@@ -29,7 +29,7 @@
<ul class="blocks-gallery-grid">
<li class="blocks-gallery-item">
<figure>
-<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" data-full-url="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg" class="wp-image-243"/>
+<img src="https://onetwoonetwothisisjustatesthome.files.wordpress.com/2019/12/pexels-photo-1260968.jpeg?w=683" alt="" data-id="243" class="wp-image-243"/>
</figure>
</li>
</ul> However, in the case of "Link To" == "None", or "Attachment Page", the block is recovered, and displayed normally. Only the "Media File" gallery block fails to display. One notable difference in the html that renders for the gallery block with "Link To" == "Media File" is that the images are wrapped in an I was also able to reproduce the validation failure via the web block editor with the following steps:
Result:
Appending |
hey @jorgefilipecosta 👋 is this something you heard of? Gallery block becomes invalid if link is set to |
I have confirmed that this is also true when saving and re-opening a post on web for the .com sites. The omission of |
WordPress.com has more strict security requirements around the use of data attributes – some background can be found in D23463-code. |
Thanks Kirk for the info. I believe this is indeed the root of the issue we're encountering. @jorgefilipecosta, I had some success with the following (somewhat crude) workaround: diff --git a/packages/block-library/src/gallery/save.js b/packages/block-library/src/gallery/save.js
index 9981c0285..0bb9eeda8 100644
--- a/packages/block-library/src/gallery/save.js
+++ b/packages/block-library/src/gallery/save.js
@@ -8,6 +8,10 @@ import { RichText } from '@wordpress/block-editor';
*/
import { defaultColumnsNumber } from './shared';
+// workaround to get fullUrl from url when image.fullURL is not defined
+// (strips `?w=size` from url string)
+const stripUrlParameters = url => url.split( '?' )[ 0 ];
+
export default function save( { attributes } ) {
const { images, columns = defaultColumnsNumber( attributes ), imageCrop, caption, linkTo } = attributes;
@@ -19,7 +23,7 @@ export default function save( { attributes } ) {
switch ( linkTo ) {
case 'media':
- href = image.fullUrl || image.url;
+ href = image.fullUrl || stripUrlParameters( image.url );
break;
case 'attachment':
href = image.link; Which assumes that we can safely fallback to using a parameterless url as the full url when |
This is being addressed on .com(D36576-code) so currently no need to make workarounds on Core side as they might introduce other issues. |
Describe the bug
This is not not reproducible on atomic sites, but only other paid plan sites. This looks similar to the problem we currently have on Video block where Jetpack changes the output html in a way that not valid on Core. So maybe it won't have a solution on our side but definitely needs investigation.
To Reproduce
Expected behavior
No validation errors.
Screenshots
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: