From 7d522a09acab646ff03f66b042e4b46f49f9fbe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Wed, 23 Nov 2022 15:10:10 +0100 Subject: [PATCH] #556: check SMS message for HTML which would be printed as-is on phones --- docs/dist/documentation.md | 13 +++++++++++++ lib/metadataTypes/TransactionalSMS.js | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index 147ac47db..ac42e2b67 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -4376,6 +4376,7 @@ TransactionalSMS MetadataType * [._mergeCode(metadata, deployDir, [templateName])](#TransactionalSMS._mergeCode) ⇒ Promise.<string> * [.postRetrieveTasks(metadata)](#TransactionalSMS.postRetrieveTasks) ⇒ TYPE.CodeExtractItem * [.prepExtractedCode(metadataScript)](#TransactionalSMS.prepExtractedCode) ⇒ Object + * [._isHTML(code)](#TransactionalSMS._isHTML) ⇒ boolean * [.getFilesToCommit(keyArr)](#TransactionalSMS.getFilesToCommit) ⇒ Array.<string> @@ -4502,6 +4503,18 @@ helper for [parseMetadata](parseMetadata) and [_buildForNested](_buildForNested) | --- | --- | --- | | metadataScript | string | the code of the file | + + +### TransactionalSMS.\_isHTML(code) ⇒ boolean +very simplified test for HTML code in our SMS + +**Kind**: static method of [TransactionalSMS](#TransactionalSMS) +**Returns**: boolean - true if HTML is found + +| Param | Type | Description | +| --- | --- | --- | +| code | string | sms source code | + ### TransactionalSMS.getFilesToCommit(keyArr) ⇒ Array.<string> diff --git a/lib/metadataTypes/TransactionalSMS.js b/lib/metadataTypes/TransactionalSMS.js index fbc2d79a1..31a3faf5f 100644 --- a/lib/metadataTypes/TransactionalSMS.js +++ b/lib/metadataTypes/TransactionalSMS.js @@ -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 @@ -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 { @@ -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