8
0
Prechádzať zdrojové kódy

Merge branch 'master' of https://github.com/amrita-syn/ckeditor5-paste-from-office into amrita-syn-master

Piotrek Koszuliński 6 rokov pred
rodič
commit
4d3c4b0f38

+ 4 - 1
packages/ckeditor5-paste-from-office/src/filters/space.js

@@ -41,7 +41,10 @@ export function normalizeSpacerunSpans( htmlDocument ) {
 	htmlDocument.querySelectorAll( 'span[style*=spacerun]' ).forEach( el => {
 		// Use `el.childNodes[ 0 ].data.length` instead of `el.innerText.length`. For `el.innerText.length` which
 		// contains spaces mixed with ` ` Edge browser returns incorrect length.
-		const innerTextLength = el.childNodes[ 0 ].data.length;
+		const innerTextLength = ( el.childNodes &&
+			el.childNodes[ 0 ] &&
+			el.childNodes[ 0 ].data &&
+			el.childNodes[ 0 ].data.length ) || 0;
 
 		el.innerHTML = Array( innerTextLength + 1 ).join( '\u00A0 ' ).substr( 0, innerTextLength );
 	} );

+ 16 - 0
packages/ckeditor5-paste-from-office/tests/filters/space.js

@@ -98,6 +98,22 @@ describe( 'PasteFromOffice - filters', () => {
 
 				normalizeSpacerunSpans( htmlDocument );
 
+				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
+			} );
+			it( 'should normalize spaces inside special "span.spacerun" elements that contain no data', () => {
+				const input = '<p> <span style=\'mso-spacerun:yes\'>   </span>Foo</p>' +
+					'<p> Baz <span style=\'mso-spacerun:yes\'></span></p>';
+
+				const expected = '<p> <span style="mso-spacerun:yes">&nbsp; &nbsp;</span>Foo</p>' +
+					'<p> Baz <span style="mso-spacerun:yes"></span></p>';
+
+				const domParser = new DOMParser();
+				const htmlDocument = domParser.parseFromString( input, 'text/html' );
+
+				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.not.equal( expected );
+
+				normalizeSpacerunSpans( htmlDocument );
+
 				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
 			} );
 		} );