Skip to content

Commit

Permalink
#556: check SMS message for HTML which would be printed as-is on phones
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Nov 23, 2022
1 parent ecb3ddb commit 7d522a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4376,6 +4376,7 @@ TransactionalSMS MetadataType
* [._mergeCode(metadata, deployDir, [templateName])](#TransactionalSMS._mergeCode) ⇒ <code>Promise.&lt;string&gt;</code>
* [.postRetrieveTasks(metadata)](#TransactionalSMS.postRetrieveTasks) ⇒ <code>TYPE.CodeExtractItem</code>
* [.prepExtractedCode(metadataScript)](#TransactionalSMS.prepExtractedCode) ⇒ <code>Object</code>
* [._isHTML(code)](#TransactionalSMS._isHTML) ⇒ <code>boolean</code>
* [.getFilesToCommit(keyArr)](#TransactionalSMS.getFilesToCommit) ⇒ <code>Array.&lt;string&gt;</code>

<a name="TransactionalSMS.retrieve"></a>
Expand Down Expand Up @@ -4502,6 +4503,18 @@ helper for [parseMetadata](parseMetadata) and [_buildForNested](_buildForNested)
| --- | --- | --- |
| metadataScript | <code>string</code> | the code of the file |

<a name="TransactionalSMS._isHTML"></a>

### TransactionalSMS.\_isHTML(code) ⇒ <code>boolean</code>
very simplified test for HTML code in our SMS

**Kind**: static method of [<code>TransactionalSMS</code>](#TransactionalSMS)
**Returns**: <code>boolean</code> - true if HTML is found

| Param | Type | Description |
| --- | --- | --- |
| code | <code>string</code> | sms source code |

<a name="TransactionalSMS.getFilesToCommit"></a>

### TransactionalSMS.getFilesToCommit(keyArr) ⇒ <code>Array.&lt;string&gt;</code>
Expand Down
27 changes: 27 additions & 0 deletions lib/metadataTypes/TransactionalSMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ class TransactionalSMS extends MetadataType {
message: await this._mergeCode(metadata, dir),
};

if (this._isHTML(metadata.content?.message)) {
// keep this as a non-blocking warning because the test not 100% accurate
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
metadata[this.definition.keyField]
}): HTML detected`
);
}

// subscriptions: mobileCode
if (metadata.subscriptions?.shortCode) {
// we merely want to be able to show an error if it does not exist
Expand Down Expand Up @@ -200,6 +209,15 @@ class TransactionalSMS extends MetadataType {
fileExt: fileExt,
content: code,
});

if (this._isHTML(code)) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
metadata[this.definition.keyField]
}): HTML detected`
);
}

// subscriptions: mobileCode
if (metadata.subscriptions?.shortCode) {
try {
Expand Down Expand Up @@ -270,6 +288,15 @@ class TransactionalSMS extends MetadataType {

return { fileExt, code };
}
/**
* very simplified test for HTML code in our SMS
*
* @param {string} code sms source code
* @returns {boolean} true if HTML is found
*/
static _isHTML(code) {
return /(<([^>]+)>)/gi.test(code);
}
/**
* should return only the json for all but asset, query and script that are saved as multiple files
* additionally, the documentation for dataExtension and automation should be returned
Expand Down

0 comments on commit 7d522a0

Please sign in to comment.