Skip to content

Commit

Permalink
[Mobile] - Crash fixes when pasting HTML content (#60676)
Browse files Browse the repository at this point in the history
* Mobile - JSdom - Add dataset polyfill

* Mobile - image-corrector - Set empty src attribute for file: values

* Mobile - Jest config - Enable 	special-comment-converter tests

* Update Changelog

* Replace const name

Co-authored-by: geriux <geriux@git.wordpress.org>
Co-authored-by: twstokes <twstokes@git.wordpress.org>
  • Loading branch information
3 people committed Apr 24, 2024
1 parent 58b8abc commit 562e10a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default function imageCorrector( node ) {
return;
}

if ( node.src.indexOf( 'file:' ) === 0 ) {
node.setAttribute( 'src', '' );
}

// Remove trackers and hardly visible images.
if ( node.height === 1 || node.width === 1 ) {
node.parentNode.removeChild( node );
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For each user feature we should also add a importance categorization label to i
-->

## Unreleased
- [*] Fix a crash when pasting file images and special comment markup [#60476]

## 1.117.0
- [*] Add empty fallback option for the BottomSheetSelectControl component [#60333]
Expand Down
31 changes: 31 additions & 0 deletions packages/react-native-editor/src/jsdom-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,37 @@ Object.defineProperties( Node.prototype, {
return sibling;
},
},
dataset: {
get() {
const node = this;

// Helper function to convert property name to data-* attribute name
function toDataAttributeName( property ) {
return (
'data-' +
property.replace(
/[A-Z]/g,
( match ) => '-' + match.toLowerCase()
)
);
}
return new Proxy(
{},
{
set( _target, property, value ) {
const attributeName = toDataAttributeName( property );
node.setAttribute( attributeName, value );
return true;
},
get( _target, property ) {
const attributeName = toDataAttributeName( property );
return node.getAttribute( attributeName );
},
}
);
},
set() {},
},
} );

class DOMParser {
Expand Down
1 change: 0 additions & 1 deletion test/native/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const RAW_HANDLING_UNSUPPORTED_UNIT_TESTS = [
'html-formatting-remover',
'phrasing-content-reducer',
'figure-content-reducer',
'special-comment-converter',
'normalise-blocks',
'image-corrector',
];
Expand Down

0 comments on commit 562e10a

Please sign in to comment.