WP Stories: relaxing the HEADING_END definition to avoid IOB #14465
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.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #13697
The PR is too simple, but it's all what's needed in order to circumvent this problem.
As explained in #13697 (comment) I was able to reproduce and explain this issue.
The problem is, having a Story block and trying to edit the Post in Aztec will make it invisible to the user. Then the user might try adding an image in the place where the Story was, and Aztec will then break the Story block structure, making it invalid for Gutenberg and causing trouble in our integration in WPAndroid when processing the
mediaFiles
attribute.This is a sample content before editing with Aztec:
And this is the content at the time of crashing, after editing with Aztec and trying to add an image:
This situation will be avoided altogether at least for simple sites by having the switch to classic editor button removed in
17.1
(*), but nonetheless users who already have written a Post and modified it like this will keep running into it, so I also went ahead and added a check to avoid running into IOB situation.The particular problem here is editing on Aztec will remove the Story block header's new line we expect to find in
const val HEADING_END = " -->\n"
. If you check the reported content, it starts like this:<!-- wp:jetpack/story --><div class...
. So this PR just relaxes theHEADING_END
matcher a bit and only defines the closing comment tag, as in" -->"
. This prevents the issue from happening (although of course nothing can be done in terms of having the block already mangled). Gutenberg will detect this invalidity at least.(*) context: see deprecation of Aztec related PRs #14381 (use Block Editor by default) and #14334 (removal of "Switch to classic editor" option in the Editor menu)
Also see:
p7cLQ7-1sn-p2
And:
p1618236627386400-slack-C6UJ0KRKQ
To Test:
checkout and install version 17.0 of WPAndroid https://github.com/wordpress-mobile/WordPress-Android/releases/download/17.0/wpandroid-17.0-signed.apk (I recommend instead checking out the commit hash and building so you can then apply this patch easily - you can find the associate commit hash here e8490c9)
remember to
git submodule update --recursive
if you want to build gutenberg from source, or comment the following line in gradle.properties# wp.BUILD_GUTENBERG_FROM_SOURCE = true
(or set it to false)create a Post with Gutenberg on mobile
add a Story block. Please now add an image to it. If you leave the Story block empty, you'll hit the other IOB exception handled in Stories: add bounds check in saving, don't process an empty Story block #14460. (I was tempted to make the change on that PR but I wanted to keep things separate to be able to explain how we came about this).
now switch to classic editor (Aztec)
the cursor will be found at the start (sometimes it doesn't appear blinking, but internally it's pointing to the beginning of content)
add an image
observe the image is displayed and the upload progress starts, but then everything freezes.
the logs show an infinite loop of this:
Regression Notes
Potential unintended areas of impact
UploadService, but only when switching between editors.
What I did to test those areas of impact (or what existing automated tests I relied on)
Tested adding media manually, and verified the current tests still run
What automated tests I added (or what prevented me from doing so)
Tested adding media manually, and verified the current tests still run
PR submission checklist:
RELEASE-NOTES.txt
if necessary.