Skip to content
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

[Mobile] - Crash fixes when pasting HTML content #60676

Merged
merged 8 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading