11import Bluebird from 'bluebird' ;
22import * as url from 'url' ;
33import * as path from 'path' ;
4- import { ContentstackClient , managementSDKClient } from '@contentstack/cli-utilities' ;
4+ import { ContentstackClient , managementSDKClient , replaceNonAlphanumericWithEmpty , isValidURL } from '@contentstack/cli-utilities' ;
55import { ImportConfig } from '../types' ;
66const debug = require ( 'debug' ) ( 'util:requests' ) ;
77let _ = require ( 'lodash' ) ;
@@ -255,8 +255,10 @@ export const lookupAssets = function (
255255 // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&');
256256 // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&');
257257 // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
258- entry = entry . replace ( new RegExp ( assetUrl , 'img' ) , mappedAssetUrl ) ;
259- matchedUrls . push ( mappedAssetUrl ) ;
258+ if ( isValidURL ( mappedAssetUrl ) ) {
259+ entry = entry . replace ( new RegExp ( assetUrl , 'img' ) , mappedAssetUrl ) ;
260+ matchedUrls . push ( mappedAssetUrl ) ;
261+ }
260262 } else {
261263 unmatchedUrls . push ( assetUrl ) ;
262264 }
@@ -265,7 +267,8 @@ export const lookupAssets = function (
265267 assetUids . forEach ( function ( assetUid : any ) {
266268 let uid = mappedAssetUids [ assetUid ] ;
267269 if ( typeof uid !== 'undefined' ) {
268- const escapedAssetUid = assetUid . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
270+ let escapedAssetUid = assetUid . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
271+ escapedAssetUid = replaceNonAlphanumericWithEmpty ( escapedAssetUid )
269272 const regex = new RegExp ( `\\b${ escapedAssetUid } \\b` , 'img' ) ;
270273 entry = entry . replace ( regex , uid ) ;
271274 matchedUids . push ( assetUid ) ;
0 commit comments