Skip to content

Commit

Permalink
Merge pull request #1158 from Accenture/bugfix/1157-mcdev-strips-cont…
Browse files Browse the repository at this point in the history
…ent-before-and-after-script-tag-upon-retrieval

Bugfix/1157 mcdev strips content before and after script tag upon retrieval
  • Loading branch information
JoernBerkefeld authored Jan 8, 2024
2 parents 8e008d3 + 40b8237 commit 64f512d
Show file tree
Hide file tree
Showing 10 changed files with 558 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,9 @@ export const Util = {
// \s* whitespace characters, zero or more times
// [^>]*? any character that is not a >, zero or more times, un-greedily
// (.*) capture any character, zero or more times
// /ms multiline and dotall flags
// /s dotall flag
// ideally the code looks like <script runat="server">...</script>
const scriptRegex = /^<\s*script [^>]*?>(.*)<\/\s*script\s*>$/ms;
const scriptRegex = /^<\s*script [^>]*?>(.*)<\/\s*script\s*>$/s;
code = code.trim();
const regexMatches = scriptRegex.exec(code);
if (regexMatches?.length > 1) {
Expand Down
4 changes: 3 additions & 1 deletion test/resourceFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export const soapUrl =
export const handleRESTRequest = async (config) => {
try {
// check if filtered
const urlObj = new URL(config.baseURL + config.url.slice(1));
const urlObj = new URL(
config.baseURL + (config.url.startsWith('/') ? config.url.slice(1) : config.url)
);
let filterName;
if (urlObj.searchParams.get('$filter')) {
filterName = urlObj.searchParams.get('$filter').split(' eq ')[1];
Expand Down
13 changes: 13 additions & 0 deletions test/resources/9999999/asset/block-1157-retrieve-expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table cellpadding="0" cellspacing="0" width="100%" role="presentation" style="min-width: 100%; " class="stylingblock-content-wrapper"><tr><td class="stylingblock-content-wrapper camarker-inner"><div>
my 1st html
</div>
%%[
/* my ampscript */
]%%
<script runat="server">
// my ssjs
</script>

<div>
my 2nd html
</div></td></tr></table>
41 changes: 41 additions & 0 deletions test/resources/9999999/asset/block-1157-retrieve-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"customerKey": "mcdev-issue-1157",
"assetType": {
"name": "htmlblock",
"displayName": "HTML Block"
},
"fileProperties": {
"fileName": "mcdev-issue-1157-Mcdev-strips-content"
},
"name": "mcdev-issue-1157-Mcdev-strips-content",
"owner": {
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)"
},
"createdDate": "2024-01-08T08:26:58.277-06:00",
"createdBy": {
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)"
},
"modifiedDate": "2024-01-08T08:28:01.6-06:00",
"modifiedBy": {
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)"
},
"memberId": 9999999,
"status": {
"name": "Draft"
},
"design": "",
"meta": {
"wrapperStyles": {
"mobile": {
"visible": true
},
"styling": {}
}
},
"availableViews": [],
"modelVersion": 2,
"r__folder_Path": "Content Builder"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"customerKey": "mobileMessage_test",
"assetType": {
"name": "jsonmessage",
"displayName": "JSON Message"
},
"name": "Mobile Message November 22, 2021(4:20:55 PM)",
"owner": {
"email": "[email protected]",
"name": "Jörn Berkefeld"
},
"createdDate": "2021-11-22T09:21:11.933-06:00",
"createdBy": {
"email": "[email protected]",
"name": "Jörn Berkefeld"
},
"modifiedDate": "2021-12-16T02:56:24.29-06:00",
"modifiedBy": {
"name": "SFMC DEVOPS app user"
},
"memberId": 9999999,
"status": {
"name": "Draft"
},
"views": {
"push": {
"thumbnail": {},
"content": "<!doctype html>\n<html>\n\t<head>\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t\t<meta name=\"description\" content=\"Push Preview\">\n\t\t<style>\n\thtml,\n\tbody {\n\t\tmargin: 0;\n\t\tpadding: 0;\n\t\theight: 100%;\n\t\twidth: 100%;\n\t\tline-height: 1.4;\n\t}\n\n\t.push-previewer {\n\t\twidth: inherit;\n\t\theight: inherit;\n\t\tposition: relative;\n\t}\n\n\t.device {\n\t\theight: inherit;\n\t\twidth: inherit;\n\t\tbackground-size: cover;\n\t\tbackground-repeat: no-repeat;\n\t}\n</style> <style>\n\t@font-face {\n\t\tfont-family: 'SF Pro Text - Regular';\n\t\tsrc: url('https://mobilepush-device-previewer.s7.marketingcloudapps.com/fonts/SFProText-Regular.woff') format('woff');\n\t\tfont-weight: normal;\n\t\tfont-style: normal;\n\t}\n\t\n\t@font-face {\n\t\tfont-family: 'Helvetica Neue - Roman';\n\t\tsrc: url('https://mobilepush-device-previewer.s7.marketingcloudapps.com/fonts/HelveticaNeue-Roman.woff') format('woff');\n\t\tfont-weight: normal;\n\t\tfont-style: normal;\n\t}\n\t\n\t@font-face {\n\t\tfont-family: 'SF Compact Text - Light';\n\t\tsrc: url('https://mobilepush-device-previewer.s7.marketingcloudapps.com/fonts/SFCompactText-Light.woff') format('woff');\n\t\tfont-weight: normal;\n\t\tfont-style: normal;\n\t}\n\t\n\t.device.iphone.lock-screen {\n\t\tfont-family: 'SF Pro Text - Regular';\n\t\tbackground-image: url('https://image.s8.exacttarget.com/lib/fe8e1c72746d057a70/m/1/d1948d1e-93af-4b9d-8b28-a087a351e8a8.jpg');\n\t}\n\t\n\t.device.iphone.lock-screen .header {\n\t\ttext-align: center;\n\t\tmargin-bottom: 20px;\n\t}\n\t\n\t.device.iphone.lock-screen .header .time {\n\t\tcolor: #FFFFFF;\n\t\tfont-family: 'SF Compact Text - Light';\n\t\tfont-size: 60px;\n\t\theight: 70px;\n\t}\n\n\t.device.iphone.lock-screen .header .date {\n\t\tcolor: #FFFFFF;\n\t\tfont-family: 'Helvetica Neue - Roman';\n\t\tfont-size: 17px;\n\t}\n\t\n\t.device.iphone.lock-screen .body {\n\t\tbackground: rgba(240, 240, 240, 0.97);\n\t\tborder-radius: 12px;\n\t\tpadding: 10px;\n\t\tmargin: 0 4px;\n\t\topacity: 1;\n\t\tposition: relative;\n\t}\n\t\n\t.device.iphone.lock-screen .body .application {\n\t\tdisplay: flex;\n\t\talign-items: center;\n\t\tborder-radius: 12px 12px 0 0;\n\t\tbackground: #F0F0F0;\n\t\tmargin: -10px -10px 0 -10px;\n\t\tpadding: 10px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .application .icon {\n\t\t\n\t}\n\t\n\t.device.iphone.lock-screen .body .application .icon .icon-placeholder {\n\t\theight: 17px;\n\t\twidth: 17px;\n\t\tborder-radius: 3px;\n\t\tbackground-color: grey;\n\t\tdisplay: inline-block;\n\t\tvertical-align: middle;\n\t}\n\t\n\t.device.iphone.lock-screen .body .application .name {\n\t\tcolor: #000000;\n\t\topacity: .50;\n\t\tfont-size: 12px;\n\t\ttext-overflow: ellipsis;\n\t\toverflow: hidden;\n\t\twhite-space: nowrap;\n\t\twidth: 100%;\n\t\tpadding: 2px 5px 0 10px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .application .timestamp {\n\t\tfont-size: 11px;\n\t\topacity: .50;\n\t\tfont-weight: bold;\n\t\tmargin-left: auto;\n\t}\n\t\n\t.device.iphone.lock-screen .body .media {\n\t\tborder-radius: 3px;\n\t\twidth: 26px;\n\t\theight: 26px;\n\t\tposition: absolute;\n\t\tright: 10px;\n\t\tbottom: 10px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .media img {\n\t\theight: 100%;\n\t\tmax-height: 26px;\n\t\twidth: 100%;\n\t\tmax-width: 26px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content {\n\t\tcolor: #000000;\n\t\tfont-size: 13px;\n\t\tpadding-top: 5px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content > div {\n\t\ttext-overflow: ellipsis;\n\t\toverflow: hidden;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content .title {\n\t\tfont-weight: bold;\n\t\twhite-space: nowrap;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content .subtitle {\n\t\tfont-weight: bold;\n\t\twhite-space: nowrap;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content .message {\n\t\twhite-space: pre-wrap;\n\t\tdisplay: -webkit-box;\n\t\t-webkit-line-clamp: 4;\n\t\t-webkit-box-orient: vertical;\n\t\ttext-overflow: ellipsis;\n\t\t-o-text-overflow: ellipsis;\n\t\t-ms-text-overflow: ellipsis;\n\t\tword-break: break-word;\n\t\t-ms-word-wrap: break-word;\n\t\tword-wrap: break-word;\n\t\tmax-height: 75px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content .message.hasTitle {\n\t\tmax-height: 55px;\n\t\t-webkit-line-clamp: 3;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content .message.hasSubtitle {\n\t\tmax-height: 35px;\n\t\t-webkit-line-clamp: 2;\n\t}\n\t\n\t.device.iphone.lock-screen .body .content.hasMedia .message {\n\t\tpadding-right: 50px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .action {\n\t\tcolor: #157EBF;\n\t\tfont-size: 11px;\n\t\topacity: .3;\n\t\tmargin-top: 5px;\n\t}\n\t\n\t.device.iphone.lock-screen .body .buttons {\n\t\tdisplay: none;\n\t}\n\t\n\t.device.iphone.lock-screen .footer {\n\t\tdisplay: none;\n\t}\n</style>\n\t</head>\n\t<body>\n\t\t<div class=\"push-previewer\">\n\t\t\t<div class=\"device iphone lock-screen\">\n\t\t\t\t<div class=\"header\">\n\t\t\t\t\t<div class=\"time\">12:00 AM</div>\n\t\t\t\t\t<div class=\"date\">January 1, 2020</div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"body\">\n\t\t\t\t\t<div class=\"application\">\n\t\t\t\t\t\t<div class=\"icon\">\n\t\t\t\t\t\t\t<div class=\"icon-placeholder\"></div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"name\">App Name</div>\n\t\t\t\t\t\t<div class=\"timestamp\">now</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"media\"></div>\n\t\t\t\t\t<div class=\"content \">\n\t\t\t\t\t\t<div class=\"title\">test</div>\n\t\t\t\t\t\t<div class=\"subtitle\"></div>\n\t\t\t\t\t\t<div class=\"message hasTitle \">asdfasf </div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"action\"></div>\n\t\t\t\t\t<div class=\"buttons\">\n\t\t\t\t\t\t<div class=\"button1\"></div>\n\t\t\t\t\t\t<div class=\"button2\"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"footer\"></div>\n\t\t\t</div>\n\t\t</div>\n\t</body>\n</html>",
"meta": {
"options": {
"customBlockData": {
"display:title": "test",
"channel": "push",
"showTemplatePicker": false,
"display:title:display": "test",
"stack": "S7",
"openBehavior:actionType": {
"label": "Open the App",
"value": "openApp",
"id": "openApp_0",
"localizedLabel": "Open the App"
},
"display:message": "asdfasf ",
"currentColumn": 0,
"display:message:display": "asdfasf ",
"template": "push",
"uncheckedPanels": ["pushmedia", "subtitle"]
}
}
},
"modelVersion": 2
}
},
"availableViews": ["push"],
"modelVersion": 2,
"category": {
"id": 89397,
"name": "Content Builder",
"parentId": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"id": 1295064,
"customerKey": "mcdev-issue-1157",
"objectID": "972974ed-dc44-4df2-ab6e-53bae9070339",
"assetType": {
"id": 197,
"name": "htmlblock",
"displayName": "HTML Block"
},
"fileProperties": {
"fileName": "mcdev-issue-1157-Mcdev-strips-content"
},
"name": "mcdev-issue-1157-Mcdev-strips-content",
"owner": {
"id": 700301950,
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)",
"userId": "700301950"
},
"createdDate": "2024-01-08T08:26:58.277-06:00",
"createdBy": {
"id": 700301950,
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)",
"userId": "700301950"
},
"modifiedDate": "2024-01-08T08:28:01.6-06:00",
"modifiedBy": {
"id": 700301950,
"email": "[email protected]",
"name": "Jörn Berkefeld (ASGR)",
"userId": "700301950"
},
"enterpriseId": 9999999,
"memberId": 9999999,
"status": {
"id": 1,
"name": "Draft"
},
"thumbnail": {
"thumbnailUrl": "/v1/assets/1295064/thumbnail"
},
"category": {
"id": 89397,
"name": "Content Builder",
"parentId": 0
},
"content": "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" role=\"presentation\" style=\"min-width: 100%; \" class=\"stylingblock-content-wrapper\"><tr><td class=\"stylingblock-content-wrapper camarker-inner\"><div>\n my 1st html\n</div>\n\n%%[ /* my ampscript */ ]%%\n\n<script runat=\"server\">\n// my ssjs\n</script>\n\n<div>\n my 2nd html\n</div></td></tr></table>",
"design": "",
"meta": {
"wrapperStyles": {
"mobile": {
"visible": true
},
"styling": {}
}
},
"availableViews": [],
"modelVersion": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"id": 808714,
"customerKey": "testExisting_asset_message",
"objectID": "01f883be-c5c3-4eb1-b6e1-d7036f8153d4",
"contentType": "application/vnd.etmc.email.Message; kind=paste",
"assetType": {
"id": 208,
"name": "htmlemail",
"displayName": "HTML Email"
},
"name": "testExisting_asset_message",
"owner": {
"id": 717129834,
"email": "[email protected]",
"name": "Jörn Berkefeld",
"userId": "717129834"
},
"createdDate": "2020-03-06T02:35:15.677-06:00",
"createdBy": {
"id": 717129834,
"email": "[email protected]",
"name": "Jörn Berkefeld",
"userId": "717129834"
},
"modifiedDate": "2023-08-02T07:08:00.86-06:00",
"modifiedBy": {
"id": 700304523,
"name": "SFMC DEVOPS app user",
"userId": "700304523"
},
"enterpriseId": 7281698,
"memberId": 7281698,
"status": {
"id": 1,
"name": "Draft"
},
"thumbnail": {
"thumbnailUrl": "/v1/assets/808714/thumbnail"
},
"category": {
"id": 89397,
"name": "Content Builder",
"parentId": 0
},
"views": {
"subjectline": {
"contentType": "application/vnd.etmc.email.View; kind=subjectline",
"thumbnail": {},
"content": "TEST",
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"preheader": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"html": {
"thumbnail": {},
"content": "<a href=\"%%ftaf_url%%\"\n ><img\n src=\"https://www.exacttarget.com/members/newsletters/gfx/forwardafriendicon.gif\"\n border=\"0\" /></a\n><a href=\"%%profile_center_url%%\" alias=\"Update Profile\">Update Profile</a>\n<table cellpadding=\"2\" cellspacing=\"0\" width=\"600\" id=\"Table5\" border=\"0\">\n <tr>\n <td>\n <font face=\"verdana\" size=\"1\" color=\"#444444\"\n >This email was sent by: <b>%%Member_Busname%%</b><br />%%Member_Addr%%\n %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br /><br\n /></font>\n </td>\n </tr>\n</table>\n<a href=\"%%subscription_center_url%%\" alias=\"Manage Subscriptions\">Manage Subscriptions</a\n><img src=\"https://www.exacttarget.com/images/Powered_By_1206.jpg\" border=\"0\" /><custom\n name=\"opencounter\"\n type=\"tracking\"\n/>\n",
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"text": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": "html"
}
}
},
"generateFrom": "html",
"modelVersion": 2
},
"viewAsAWebPage": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"subscriptioncenter": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"forwardHTML": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
},
"forwardText": {
"thumbnail": {},
"availableViews": [],
"data": {
"email": {
"options": {
"generateFrom": null
}
}
},
"modelVersion": 2
}
},
"availableViews": [
"subjectline",
"preheader",
"html",
"text",
"viewAsAWebPage",
"subscriptioncenter",
"forwardHTML",
"forwardText"
],
"data": {
"email": {
"options": {
"characterEncoding": "utf-8"
},
"legacy": {
"legacyId": 429827,
"legacyKey": "c7308370-bb2c-4bd4-83dd-0ea422e2009d",
"legacyType": "email",
"legacyCategoryId": 90890
}
},
"approvals": {
"approvalStatus": {
"id": 4,
"name": "Approved",
"displayName": "Approved"
}
}
},
"legacyData": {
"legacyId": 429827,
"legacyKey": "c7308370-bb2c-4bd4-83dd-0ea422e2009d",
"legacyType": "email",
"legacyCategoryId": 90890
},
"modelVersion": 2
}
Loading

0 comments on commit 64f512d

Please sign in to comment.