diff --git a/Specialized Areas/Regular Expressions/Avoid Direct String in Widget HTML Templates -HealthScan Finding/README.md b/Specialized Areas/Regular Expressions/Avoid Direct String in Widget HTML Templates -HealthScan Finding/README.md new file mode 100644 index 0000000000..c8766a1900 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Avoid Direct String in Widget HTML Templates -HealthScan Finding/README.md @@ -0,0 +1,13 @@ +**Use Case** +1. Adding string in HTML template without ${} or gs.getMessage('string') in server script attracts HealthScan findings. +2. These string do not get translated in multi lingual portals. +3. This will help in ensuring internationalization. Same BR can be used in "sp_ng_template" table. + +**How to use** +1. Add this code as before insert/update BR on sp_widget table. +2. The condition will be "Body HTML Changes." +3. If Internationalisation is not followed, error message will be shown and action will be aborted. + +**Regex** +/>([a-zA-Z].*)<\// +This Regex check any direct string between > and ([a-zA-Z].*)<\//; // regex to check if strings are directly added in HTML Template + var regex = new RegExp(reg); + if (regex.test(current.getValue('template'))) { + gs.addInfoMessage("Please use standard inernationalisation methods for strings like ${string} or define the string in server using gs.getMessage('string')"); + current.setAbortAction(true); + } + +})(current, previous);