@nka212bg/backend-utils 0.1.51 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -176,7 +176,7 @@ const createInstance = (options = {}) => {
176
176
 
177
177
  const mailOptions = {
178
178
  from: name ? { name, address: smtpUser } : smtpUser,
179
- // html: handlebars({ template: defaultTemplate, content, subject, logoUrl: `${process.env.BASE_URL}/logo_black.png` }),
179
+ // html: handlebars(defaultTemplate, { content, subject, logoUrl: `${process.env.BASE_URL}/logo_black.png` }),
180
180
  html,
181
181
  subject,
182
182
  to: e,
package/misc.js CHANGED
@@ -118,17 +118,14 @@ exports.createToken = ({ length = 14, type } = {}) => {
118
118
  }
119
119
  };
120
120
 
121
- exports.handlebars = ({ template, ...params } = {}) => {
122
- const placeholders = template.match(/(\{\{)(.*?)(\}\})/g);
121
+ exports.escapeHtml = (s) => String(s).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
123
122
 
124
- for (const p in params) {
125
- const placeholder = placeholders.find((e) => e.includes(p));
126
- if (!placeholder) continue;
127
-
128
- template = template.replace(RegExp(placeholder, "g"), params[p]);
129
- }
130
-
131
- return template;
123
+ // {{ key }} → raw (trusted), {{{ key }}} → HTML-escaped (untrusted); supports nested keys like {{ user.name }}
124
+ exports.handlebars = (template = "", params = {}) => {
125
+ return template.replace(/\{\{(\{?)\s*([\w.]+)\s*\}?\}\}/g, (match, safe, key) => {
126
+ const value = key.split(".").reduce((o, k) => o?.[k], params);
127
+ return value == null ? match : safe ? this.escapeHtml(value) : value;
128
+ });
132
129
  };
133
130
 
134
131
  exports.shortCount = (value, bites) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nka212bg/backend-utils",
3
3
  "author": "nka212bg",
4
- "version": "0.1.51",
4
+ "version": "0.1.52",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@maxmind/geoip2-node": "^5.0.0",