@@ -249,16 +249,18 @@ class PreviewFrame extends React.Component {
249
249
jsFileStrings . forEach ( ( jsFileString ) => {
250
250
if ( jsFileString . match ( MEDIA_FILE_QUOTED_REGEX ) ) {
251
251
const filePath = jsFileString . substr ( 1 , jsFileString . length - 2 ) ;
252
+ const quoteCharacter = jsFileString . substr ( 0 , 1 ) ;
252
253
const resolvedFile = resolvePathToFile ( filePath , files ) ;
254
+
253
255
if ( resolvedFile ) {
254
256
if ( resolvedFile . url ) {
255
- newContent = newContent . replace ( filePath , resolvedFile . url ) ;
257
+ newContent = newContent . replace ( jsFileString , quoteCharacter + resolvedFile . url + quoteCharacter ) ;
256
258
} else if ( resolvedFile . name . match ( PLAINTEXT_FILE_REGEX ) ) {
257
259
// could also pull file from API instead of using bloburl
258
260
const blobURL = getBlobUrl ( resolvedFile ) ;
259
261
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 ) ;
262
264
}
263
265
}
264
266
}
@@ -274,10 +276,11 @@ class PreviewFrame extends React.Component {
274
276
cssFileStrings . forEach ( ( cssFileString ) => {
275
277
if ( cssFileString . match ( MEDIA_FILE_QUOTED_REGEX ) ) {
276
278
const filePath = cssFileString . substr ( 1 , cssFileString . length - 2 ) ;
279
+ const quoteCharacter = cssFileString . substr ( 0 , 1 ) ;
277
280
const resolvedFile = resolvePathToFile ( filePath , files ) ;
278
281
if ( resolvedFile ) {
279
282
if ( resolvedFile . url ) {
280
- newContent = newContent . replace ( filePath , resolvedFile . url ) ;
283
+ newContent = newContent . replace ( cssFileString , quoteCharacter + resolvedFile . url + quoteCharacter ) ;
281
284
}
282
285
}
283
286
}
0 commit comments