pawa-ssr 1.3.6 → 1.3.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.
- package/index.js +17 -16
- package/package.json +2 -2
- package/utils.js +9 -0
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {getServerInstance, setServer} from 'pawajs/server.js'
|
|
2
2
|
import { DOMParser,parseHTML, HTMLElement} from 'linkedom'
|
|
3
3
|
import PawaComponent from './pawaComponent.js'
|
|
4
|
-
import { propsValidator, evaluateExpr,extractAtExpressions, reArrangeAttri,resumeAttribute, pawaGenerateId } from './utils.js'
|
|
4
|
+
import { propsValidator, evaluateExpr,extractAtExpressions, reArrangeAttri,resumeAttribute, pawaGenerateId, escapeHtml } from './utils.js'
|
|
5
5
|
import {AsyncLocalStorage} from'node:async_hooks'
|
|
6
6
|
import { If,For,State,Switch, Key } from'./power.js';
|
|
7
7
|
import PawaElement from'./pawaElement.js'
|
|
@@ -882,7 +882,7 @@ const attributeHandler =async (el, attr) => {
|
|
|
882
882
|
const setSingle=(...string)=>{
|
|
883
883
|
string.forEach(v => singleElement.add(v))
|
|
884
884
|
}
|
|
885
|
-
setSingle('img','br')
|
|
885
|
+
setSingle('img', 'br', 'hr', 'input', 'meta', 'link', 'base', 'col', 'area', 'param', 'track', 'wbr');
|
|
886
886
|
const partlyPawajsDirective=new Set()
|
|
887
887
|
export const addToPartlyDirective=(...partly)=>{
|
|
888
888
|
partly.forEach((v)=>{
|
|
@@ -975,6 +975,8 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
975
975
|
for(const attr of attributes){
|
|
976
976
|
if (directives[attr.name]) {
|
|
977
977
|
await directives[attr.name](el,attr,stream)
|
|
978
|
+
}else if(attr.value.includes('@{')){
|
|
979
|
+
await attributeHandler(el,attr)
|
|
978
980
|
}else if (attr.name.startsWith('state-')) {
|
|
979
981
|
directives['state-'](el,attr)
|
|
980
982
|
}
|
|
@@ -1004,9 +1006,7 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
1004
1006
|
}catch(error){
|
|
1005
1007
|
console.warn(error.message,error.stack)
|
|
1006
1008
|
}
|
|
1007
|
-
}
|
|
1008
|
-
await attributeHandler(el,attr)
|
|
1009
|
-
}
|
|
1009
|
+
}
|
|
1010
1010
|
}
|
|
1011
1011
|
|
|
1012
1012
|
}
|
|
@@ -1034,27 +1034,28 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
1034
1034
|
}
|
|
1035
1035
|
}
|
|
1036
1036
|
if(!el._running){
|
|
1037
|
-
const attr=Array.from(el.attributes)
|
|
1037
|
+
const attr = Array.from(el.attributes)
|
|
1038
|
+
.map(att => `${att.name}="${escapeHtml(att.value)}"`)
|
|
1039
|
+
.join(' ');
|
|
1040
|
+
const attrStr = attr ? ` ${attr}` : '';
|
|
1038
1041
|
const isSingle=singleElement.has(el.tagName.toLowerCase())
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1042
|
+
const tagName = el.tagName.toLowerCase();
|
|
1043
|
+
|
|
1044
|
+
stream(`<${tagName}${attrStr}${isSingle ? ' />' : '>'}`);
|
|
1045
|
+
|
|
1046
|
+
if (!isSingle) {
|
|
1044
1047
|
const children = el.childNodes;
|
|
1045
1048
|
for(const child of children){
|
|
1046
1049
|
if (child.nodeType === 3) {
|
|
1047
|
-
stream(child.nodeValue)
|
|
1050
|
+
stream(escapeHtml(child.nodeValue)) // Correct: linkedom decodes entities, so we must re-encode
|
|
1048
1051
|
}else if (child.nodeType === 8) {
|
|
1049
1052
|
stream(`<!--${child.nodeValue}-->`)
|
|
1050
1053
|
}else if (child.nodeType === 1){
|
|
1051
1054
|
await render(child, el._context,stream);
|
|
1052
1055
|
}
|
|
1053
1056
|
};
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1057
|
+
stream(`</${tagName}>`)
|
|
1058
|
+
}
|
|
1058
1059
|
}
|
|
1059
1060
|
|
|
1060
1061
|
el._setError()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pawa-ssr",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"type":"module",
|
|
5
5
|
"description": "pawajs ssr libary",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"homepage": "https://github.com/Allisboy/pawajs-ssr#readme",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"linkedom": "^0.18.11",
|
|
28
|
-
"pawajs": "^1.4.
|
|
28
|
+
"pawajs": "^1.4.28"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/utils.js
CHANGED
|
@@ -246,3 +246,12 @@ export const replaceTemplateOperators = (expression) => {
|
|
|
246
246
|
.replace(/\*\//g, '`'); // Also replace closing */ with backtick if needed
|
|
247
247
|
};
|
|
248
248
|
|
|
249
|
+
export const escapeHtml = (unsafe) => {
|
|
250
|
+
if (unsafe === null || unsafe === undefined) return '';
|
|
251
|
+
return String(unsafe)
|
|
252
|
+
.replace(/&/g, "&")
|
|
253
|
+
.replace(/</g, "<")
|
|
254
|
+
.replace(/>/g, ">")
|
|
255
|
+
.replace(/"/g, """)
|
|
256
|
+
.replace(/'/g, "'");
|
|
257
|
+
};
|