diff --git a/lib/util/lookupReplaceAssets.js b/lib/util/lookupReplaceAssets.js index 1b8a47c..8952616 100644 --- a/lib/util/lookupReplaceAssets.js +++ b/lib/util/lookupReplaceAssets.js @@ -59,29 +59,54 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe assetUids = _.uniq(assetUids); assetUrls = _.uniq(assetUrls); var entry = JSON.stringify(data.entry); + // NOTE: Incase the code breaks use the commented code + // assetUids.forEach(function (assetUid) { + // var uid = mappedAssetUids[assetUid]; + // if (typeof uid !== 'undefined') { + // const cp = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + // const regexString = `${cp}`; + // entry = entry.replace(new RegExp(regexString, 'img'), uid); + // matchedUids.push(assetUid); + // } else { + // unmatchedUids.push(assetUid); + // } + // }); assetUids.forEach(function (assetUid) { var uid = mappedAssetUids[assetUid]; if (typeof uid !== 'undefined') { - const cp = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - const regexString = `${cp}`; - entry = entry.replace(new RegExp(regexString, 'img'), uid); - matchedUids.push(assetUid); + const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + entry = entry.split(escapedAssetUid).join(uid); + matchedUids.push(assetUid); } else { - unmatchedUids.push(assetUid); + unmatchedUids.push(assetUid); } - }); +}); - assetUrls.forEach(function (assetUrl) { - var url = mappedAssetUrls[assetUrl]; - if (typeof url !== 'undefined') { - const cp = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') - const regexString = `${cp}`; - entry = entry.replace(new RegExp(regexString, 'img'), url); - unmatchedUrls.push(url); - } else { + + // NOTE: Incase the code breaks use the commented code + // assetUrls.forEach(function (assetUrl) { + // var url = mappedAssetUrls[assetUrl]; + // if (typeof url !== 'undefined') { + // const cp = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + // const regexString = `${cp}`; + // entry = entry.replace(new RegExp(regexString, 'img'), url); + // unmatchedUrls.push(url); + // } else { + // unmatchedUrls.push(assetUrl); + // } + // }); +assetUrls.forEach(function (assetUrl) { + var url = mappedAssetUrls[assetUrl]; + if (typeof url !== 'undefined') { + const escapedAssetUrl = assetUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + entry = entry.split(escapedAssetUrl).join(url); + + matchedUrls.push(assetUrl); + } else { unmatchedUrls.push(assetUrl); - } - }); + } +}); + if (matchedUids.length) { var matchedAssetUids = helper.readFile(path.join(sanitizePath(assetUidMapperPath), 'matched-asset-uids.json')); diff --git a/lib/util/lookupReplaceEntries.js b/lib/util/lookupReplaceEntries.js index 86a2977..59453f7 100644 --- a/lib/util/lookupReplaceEntries.js +++ b/lib/util/lookupReplaceEntries.js @@ -126,10 +126,21 @@ module.exports = function (data, mappedUids, uidMapperPath) { uids = _.uniq(uids); var entry = JSON.stringify(data.entry); + // NOTE: Incase the code breaks use the commented code + // uids.forEach(function (uid) { + // if (mappedUids.hasOwnProperty(uid)) { + // entry = entry.replace(new RegExp(uid, "img"), mappedUids[uid]); + // mapped.push(uid); + // } else { + // unmapped.push(uid); + // } + // }); uids.forEach(function (uid) { if (mappedUids.hasOwnProperty(uid)) { - entry = entry.replace(new RegExp(uid, "img"), mappedUids[uid]); - mapped.push(uid); + const escapedUid = uid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + entry = entry.split(escapedUid).join(mappedUids[uid]); + + mapped.push(uid); } else { unmapped.push(uid); }