@@ -249,16 +249,18 @@ class PreviewFrame extends React.Component {
249249 jsFileStrings . forEach ( ( jsFileString ) => {
250250 if ( jsFileString . match ( MEDIA_FILE_QUOTED_REGEX ) ) {
251251 const filePath = jsFileString . substr ( 1 , jsFileString . length - 2 ) ;
252+ const quoteCharacter = jsFileString . substr ( 0 , 1 ) ;
252253 const resolvedFile = resolvePathToFile ( filePath , files ) ;
254+
253255 if ( resolvedFile ) {
254256 if ( resolvedFile . url ) {
255- newContent = newContent . replace ( filePath , resolvedFile . url ) ;
257+ newContent = newContent . replace ( jsFileString , quoteCharacter + resolvedFile . url + quoteCharacter ) ;
256258 } else if ( resolvedFile . name . match ( PLAINTEXT_FILE_REGEX ) ) {
257259 // could also pull file from API instead of using bloburl
258260 const blobURL = getBlobUrl ( resolvedFile ) ;
259261 this . props . setBlobUrl ( resolvedFile , blobURL ) ;
260- const filePathRegex = new RegExp ( filePath , 'gi' ) ;
261- newContent = newContent . replace ( filePathRegex , blobURL ) ;
262+
263+ newContent = newContent . replace ( jsFileString , quoteCharacter + blobURL + quoteCharacter ) ;
262264 }
263265 }
264266 }
@@ -274,10 +276,11 @@ class PreviewFrame extends React.Component {
274276 cssFileStrings . forEach ( ( cssFileString ) => {
275277 if ( cssFileString . match ( MEDIA_FILE_QUOTED_REGEX ) ) {
276278 const filePath = cssFileString . substr ( 1 , cssFileString . length - 2 ) ;
279+ const quoteCharacter = cssFileString . substr ( 0 , 1 ) ;
277280 const resolvedFile = resolvePathToFile ( filePath , files ) ;
278281 if ( resolvedFile ) {
279282 if ( resolvedFile . url ) {
280- newContent = newContent . replace ( filePath , resolvedFile . url ) ;
283+ newContent = newContent . replace ( cssFileString , quoteCharacter + resolvedFile . url + quoteCharacter ) ;
281284 }
282285 }
283286 }
0 commit comments