Skip to content

Commit

Permalink
Merge pull request #54 from contentstack/fix/sre3
Browse files Browse the repository at this point in the history
Fix/sre3
  • Loading branch information
cs-raj authored Jul 15, 2024
2 parents e86a41e + 2f7d21e commit 336e6db
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
57 changes: 41 additions & 16 deletions lib/util/lookupReplaceAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
15 changes: 13 additions & 2 deletions lib/util/lookupReplaceEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 336e6db

Please sign in to comment.