-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Gutenberg] Update VideoPress upload processor (support self-closing block tag) #18287
Conversation
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
mBlockContentDocument = isSelfClosingTag ? null : parseHTML(captures.group(3)); | ||
mClosingComment = isSelfClosingTag ? null : captures.group(4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocks with the self-closing tag won't have content so these properties are empty.
String processBlock(String block) { | ||
return processBlock(block, false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is also used in unit tests. So, in order to avoid adding the isSelfClosingTag
argument to all of them, I overloaded the function for convenience.
String blockTagSuffix = headerMatcher.group(2); | ||
Boolean isSelfClosingTag = blockTagSuffix.equals("/-->"); | ||
if (isSelfClosingTag) { | ||
positionBlockEnd = headerMatcher.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the block uses the self-closing tag, we don't need to loop over the content to find the end position.
@@ -11,7 +11,7 @@ public class MediaUploadCompletionProcessorPatterns { | |||
public static final Pattern PATTERN_BLOCK_HEADER = Pattern.compile(new StringBuilder() | |||
.append(PATTERN_BLOCK_PREFIX) | |||
.append(MediaBlockType.getMatchingGroup()) | |||
.append(").*? -->\n?") | |||
.append(").*? (/?-->)\n?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new capture group is used to determine if the block uses the self-closing tag.
if (src?.startsWith("file:") == true) { | ||
remove(SRC_ATTRIBUTE) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The src
is removed when pointing to a local file, similar to how we do in the block's logic.
@@ -37,6 +37,14 @@ class MediaUploadCompletionProcessorTest { | |||
Assertions.assertThat(blocks).isEqualTo(TestContent.newPostVideo) | |||
} | |||
|
|||
@Test | |||
fun `processPost splices id and guid for a VideoPress block`() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was added because the VideoPress block wasn't being tested against the processContent
function.
a07475c
to
63f6297
Compare
Remove unused import Remove unused import Update test: processBlock leaves VideoPress block unchanged
63f6297
to
47a25ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed uploads works as expected after exiting a post with the changes from this PR. Thank you @fluiddot for the updates! 🙌 🚀
Fixes wordpress-mobile/gutenberg-mobile#5678.
This PR updates the VideoPress upload processor following a recent change in the block format. Additionally, the upload processor logic has been updated to support the self-closing block tag (e.g.
<!-- wp:videopress/video {"id":"1234","guid":"AbCdE" /-->
), as the VideoPress block uses this format. Note that most of the changes are reverting the modifications introduced in #18187 (1419183).To test
Testing instructions copied from #18187.
Default markup examples
Example default markup before upload:
Example default markup after upload:
Markup with attributes examples
Example markup before upload:
Example markup after upload:
Regression Notes
This change could impact other upload processors due to the change related to supporting the self-closing tag.
Manually tested the VideoPress upload processor and checked the unit tests of other upload processors.
I added a test in 0d1ce8e and updated other unit tests.
PR submission checklist:
RELEASE-NOTES.txt
if necessary.UI Changes testing checklist: