@soleil-se/app-util 4.1.0 → 4.1.2
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/CHANGELOG.md +8 -0
- package/client/utils/index.js +7 -1
- package/docs/1.render.md +4 -1
- package/package.json +2 -2
- package/server/index.js +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [4.1.2] - 2021-02-24
|
|
8
|
+
### Fixed
|
|
9
|
+
- Escape tags when parsing data to prevent closure of script tags.
|
|
10
|
+
|
|
11
|
+
## [4.1.1] - 2021-02-17
|
|
12
|
+
### Fixed
|
|
13
|
+
- Validation error for `id` on script tags, even though it's allowed.
|
|
14
|
+
|
|
7
15
|
## [4.1.0] - 2021-02-17
|
|
8
16
|
### Changed
|
|
9
17
|
- Put app data and metadata in script elements instead of data attributes.
|
package/client/utils/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import getCurrentScript from './getCurrentScript';
|
|
2
2
|
|
|
3
|
+
const unescapeTags = (unsafe) => unsafe
|
|
4
|
+
.replace(/</g, '<')
|
|
5
|
+
.replace(/>/g, '>');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* JSON decode an attribute on the currentScript element.
|
|
5
9
|
* Use if attribute contains a JSON-object.
|
|
@@ -17,5 +21,7 @@ export const getAttribute = (attribute) => {
|
|
|
17
21
|
|
|
18
22
|
export const parseJson = (type) => {
|
|
19
23
|
const id = getAttribute('data-app-id');
|
|
20
|
-
|
|
24
|
+
let json = document.querySelector(`[data-id="${type}_${id}"]`)?.textContent || '{}';
|
|
25
|
+
json = unescapeTags(json);
|
|
26
|
+
return JSON.parse(json);
|
|
21
27
|
};
|
package/docs/1.render.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# Render
|
|
2
|
-
Returns HTML for a script tag with
|
|
2
|
+
Returns HTML for a script tag with the possibility to pass data from the server.
|
|
3
3
|
Framework agnostic.
|
|
4
4
|
|
|
5
|
+
Server data is embedded as JSON in script tags.
|
|
6
|
+
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#embedding_data_in_html
|
|
7
|
+
|
|
5
8
|
## index.js
|
|
6
9
|
### render([data], [settings]) ⇒ <code>String</code>
|
|
7
10
|
`@soleil-api/webapp-util/server`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Utility functions for Webapps.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"optionalDependencies": {
|
|
15
15
|
"vue": "^2.6.11"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "810b8ad5ceb960a03f7af40052b663b444763794",
|
|
18
18
|
"dependencies": {},
|
|
19
19
|
"devDependencies": {}
|
|
20
20
|
}
|
package/server/index.js
CHANGED
|
@@ -12,6 +12,10 @@ const isIE = (req) => {
|
|
|
12
12
|
return /Trident\/|MSIE/.test(userAgent);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
const escapeTags = (unsafe) => unsafe
|
|
16
|
+
.replace(/</g, '<')
|
|
17
|
+
.replace(/>/g, '>');
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Get a HTML string for rendering an application.
|
|
17
21
|
* @param {Object} [data={}] Server data that will be available in the attribute.
|
|
@@ -36,8 +40,8 @@ export function render(data, {
|
|
|
36
40
|
const appMetadata = getAppMetadata();
|
|
37
41
|
|
|
38
42
|
const mountElement = `<div id="app_mount_${appId}">${html}</div>`;
|
|
39
|
-
const metaScriptTag = `<script id="app_meta_${appId}" type="application/json">${JSON.stringify(appMetadata)}</script>`;
|
|
40
|
-
const dataScriptTag = data ? `<script id="app_data_${appId}" type="application/json">${JSON.stringify(data)}</script>` : '';
|
|
43
|
+
const metaScriptTag = `<script data-id="app_meta_${appId}" type="application/json">${JSON.stringify(appMetadata)}</script>`;
|
|
44
|
+
const dataScriptTag = data ? `<script data-id="app_data_${appId}" type="application/json">${escapeTags(JSON.stringify(data))}</script>` : '';
|
|
41
45
|
|
|
42
46
|
if (isOffline) {
|
|
43
47
|
return `
|