@emberkit/core 0.2.7 → 0.2.8

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.
@@ -2,6 +2,7 @@ import type { JSXElement, JSXElementProps, JSXNode } from '../types.js';
2
2
  export declare function getHandler(id: string): ((e: Event) => void) | undefined;
3
3
  export declare function clearHandlers(): void;
4
4
  export declare function renderElementToHTML(element: JSXElement): string;
5
+ export declare function escapeHtml(str: string): string;
5
6
  export declare function renderToString(element: JSXElement | string | null | number | unknown[]): string;
6
7
  export declare function getComponentName(type: string | ((props: JSXElementProps) => JSXNode)): string;
7
8
  export declare function createPropsProxy(props: JSXElementProps): JSXElementProps;
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/runtime/helpers/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAuBpF,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAEvE;AAED,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CA+G/D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG,MAAM,CAO/F;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,MAAM,CAM7F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CASxE"}
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/runtime/helpers/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAuBpF,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAEvE;AAED,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CA+G/D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG,MAAM,CAO/F;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,MAAM,CAM7F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CASxE"}
@@ -45,7 +45,7 @@ export function renderElementToHTML(element) {
45
45
  }
46
46
  else if (typeof result === 'string' || typeof result === 'number') {
47
47
  renderDepth--;
48
- return String(result);
48
+ return typeof result === 'string' ? escapeHtml(result) : String(result);
49
49
  }
50
50
  else if (Array.isArray(result)) {
51
51
  const r = result.map((item) => renderToString(item)).join('');
@@ -114,9 +114,9 @@ export function renderElementToHTML(element) {
114
114
  return `${cssProp}: ${val}`;
115
115
  })
116
116
  .join('; ');
117
- return ` ${key}="${styleStr}"`;
117
+ return ` ${key}="${escapeHtml(styleStr)}"`;
118
118
  }
119
- return ` ${key}="${value}"`;
119
+ return ` ${key}="${typeof value === 'string' ? escapeHtml(value) : value}"`;
120
120
  })
121
121
  .join('');
122
122
  // Register onClick handler as data attribute
@@ -134,11 +134,19 @@ export function renderElementToHTML(element) {
134
134
  renderDepth--;
135
135
  return `<${currentType}${attributes}${onclickAttr}>${innerHtml}</${currentType}>`;
136
136
  }
137
+ export function escapeHtml(str) {
138
+ return str
139
+ .replace(/&/g, '&amp;')
140
+ .replace(/</g, '&lt;')
141
+ .replace(/>/g, '&gt;')
142
+ .replace(/"/g, '&quot;')
143
+ .replace(/'/g, '&#039;');
144
+ }
137
145
  export function renderToString(element) {
138
146
  if (!element && element !== 0)
139
147
  return '';
140
148
  if (typeof element === 'string')
141
- return element;
149
+ return escapeHtml(element);
142
150
  if (typeof element === 'number')
143
151
  return String(element);
144
152
  if (Array.isArray(element))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emberkit/core",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Lightweight TypeScript-first JSX framework core",