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

Fix unwanted additional spaces added around pasted text on Windows #33607

Merged
merged 4 commits into from
Aug 12, 2021
Merged
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 @@ -69,6 +69,9 @@ export function usePasteHandler( props ) {
}
}

// Remove Windows-specific metadata appended within copied HTML text.
html = removeWindowsFragments( html );

event.preventDefault();

// Allows us to ask for this information when we get a report.
Expand Down Expand Up @@ -222,3 +225,17 @@ export function usePasteHandler( props ) {
};
}, [] );
}

/**
* Normalizes a given string of HTML to remove the Windows specific "Fragment" comments
* and any preceeding and trailing whitespace.
*
* @param {string} html the html to be normalized
* @return {string} the normalized html
*/
function removeWindowsFragments( html ) {
const startReg = /.*<!--StartFragment-->/s;
const endReg = /<!--EndFragment-->.*/s;

return html.replace( startReg, '' ).replace( endReg, '' );
}