Skip to content

Commit c9e6e62

Browse files
committed
Remove image source with local file path
1 parent f2039df commit c9e6e62

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Browser dependencies
3+
*/
4+
const { ELEMENT_NODE } = window.Node;
5+
6+
export default function( node ) {
7+
if ( node.nodeType !== ELEMENT_NODE ) {
8+
return;
9+
}
10+
11+
if ( node.nodeName !== 'IMG' ) {
12+
return;
13+
}
14+
15+
if ( node.src.indexOf( 'file:' ) !== 0 ) {
16+
return;
17+
}
18+
19+
node.src = '';
20+
}

blocks/api/paste/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import createUnwrapper from './create-unwrapper';
1616
import isInlineContent from './is-inline-content';
1717
import formattingTransformer from './formatting-transformer';
1818
import msListConverter from './ms-list-converter';
19+
import imageCorrector from './image-corrector';
1920
import { deepFilter, isInline, isSpan, isWrapper, isInvalidInline } from './utils';
2021

2122
export default function( { content: HTML, inline } ) {
@@ -47,6 +48,7 @@ export default function( { content: HTML, inline } ) {
4748
return HTML;
4849
}
4950

51+
// Context dependent filters. Needs to run before we remove tags.
5052
HTML = deepFilter( HTML, [
5153
msListConverter,
5254
] );
@@ -55,6 +57,7 @@ export default function( { content: HTML, inline } ) {
5557
formattingTransformer,
5658
stripAttributes,
5759
commentRemover,
60+
imageCorrector,
5861
createUnwrapper( ( node ) => isWrapper( node ) ),
5962
createUnwrapper( ( node ) => isSpan( node ) ),
6063
createUnwrapper( ( node ) => node.nodeName === 'O:P' ),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { equal } from 'assert';
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import imageCorrector from '../image-corrector';
10+
import { deepFilter } from '../utils';
11+
12+
describe( 'imageCorrector', () => {
13+
it( 'should correct image source', () => {
14+
const input = '<img src="file:LOW-RES.png">';
15+
const output = '<img src="">';
16+
equal( deepFilter( input, [ imageCorrector ] ), output );
17+
} );
18+
} );

blocks/api/paste/test/integration/ms-word-in.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ <h2><span lang=EN-US style='mso-ansi-language:EN-US'>This is a heading level 2<o
101101
<o:lock v:ext="edit" aspectratio="t"/>
102102
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1025" type="#_x0000_t75"
103103
style='width:451pt;height:338pt;visibility:visible;mso-wrap-style:square'>
104-
<v:imagedata src="file:////Users/iseulde/Library/Group%20Containers/UBF8T346G9.Office/msoclip1/01/clip_image001.jpg"
104+
<v:imagedata src="file:ORIGINAL.jpg"
105105
o:title=""/>
106106
</v:shape><![endif]--><![if !vml]><img border=0 width=451 height=338
107-
src="file:////Users/iseulde/Library/Group%20Containers/UBF8T346G9.Office/msoclip1/01/clip_image002.png"
107+
src="file:LOW-RES.png"
108108
v:shapes="Picture_x0020_1"><![endif]></span><span lang=EN-US style='mso-ansi-language:
109109
EN-US'><o:p></o:p></span></p>

blocks/api/paste/test/integration/ms-word-out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ <h2>This is a heading level 2</h2>
4545
<!-- /wp:core/paragraph -->
4646

4747
<!-- wp:core/image -->
48-
<figure class="wp-block-image"><img src="file:////Users/iseulde/Library/Group%20Containers/UBF8T346G9.Office/msoclip1/01/clip_image002.png" /></figure>
48+
<figure class="wp-block-image"><img src="" /></figure>
4949
<!-- /wp:core/image -->

0 commit comments

Comments
 (0)