-
Notifications
You must be signed in to change notification settings - Fork 4.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
[RNMobile] Fix pasting HTML into the post title #57118
Conversation
This logic is a duplicate of the web implementation.
The file has been renamed to a proper name now that provides different getters for the editor content.
Now it exports modules using wildcard, instead of needing to specify every single item.
@@ -57,31 +58,45 @@ class PostTitle extends Component { | |||
this.props.onSelect(); | |||
} | |||
|
|||
onPaste( { value, onChange, plainText, html } ) { | |||
onPaste( { value, plainText, html } ) { |
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 changes made to this handler are based on the web implementation:
gutenberg/packages/editor/src/components/post-title/index.js
Lines 122 to 162 in ab04a95
if ( ! content.length ) { | |
return; | |
} | |
if ( typeof content !== 'string' ) { | |
const [ firstBlock ] = content; | |
if ( | |
! title && | |
( firstBlock.name === 'core/heading' || | |
firstBlock.name === 'core/paragraph' ) | |
) { | |
// Strip HTML to avoid unwanted HTML being added to the title. | |
// In the majority of cases it is assumed that HTML in the title | |
// is undesirable. | |
const contentNoHTML = stripHTML( | |
firstBlock.attributes.content | |
); | |
onUpdate( contentNoHTML ); | |
onInsertBlockAfter( content.slice( 1 ) ); | |
} else { | |
onInsertBlockAfter( content ); | |
} | |
} else { | |
const value = { | |
...create( { html: title } ), | |
...selection, | |
}; | |
// Strip HTML to avoid unwanted HTML being added to the title. | |
// In the majority of cases it is assumed that HTML in the title | |
// is undesirable. | |
const contentNoHTML = stripHTML( content ); | |
const newValue = insert( value, create( { html: contentNoHTML } ) ); | |
onUpdate( toHTMLString( { value: newValue } ) ); | |
setSelection( { | |
start: newValue.start, | |
end: newValue.end, | |
} ); | |
} |
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
Flaky tests detected in 1a0dc6c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7224995333
|
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.
Thank you for addressing this. I verified the crash and fix on a Pixel emulator.
I'd like to note that I haven't updated the |
* Update paste handler of post title This logic is a duplicate of the web implementation. * Allow set initial title in integration tests * Add `getEditorTitle` test helper The file has been renamed to a proper name now that provides different getters for the editor content. * Update index of integration test helpers Now it exports modules using wildcard, instead of needing to specify every single item. * Add integration tests of `PostTitle` component
What?
Updates paste handler logic of the post title to prevent an exception/crash when pasting HTML content.
Why?
This PR is needed to prevent an exception/crash.
How?
If the first element of the HTML pasted in the post title is a paragraph or heading tag, the paste handler will obtain its content:
gutenberg/packages/editor/src/components/post-title/index.native.js
Line 79 in d791ac8
Similar to the issue addressed in #57028, the value provided by the
RichText
can't be treated as a string. Hence, the above line will produce the exception/crash.This has been solved by utilizing the
toString
function to get the content, this is the same approach used in #57028.Additionally, we introduced integration tests to cover this case and others related to pasting content in the post title. In relation to this, some modifications have been applied to the test helpers derived from the test implementation.
Testing Instructions
Howdy
).Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A