Skip to content

feat(framework): Expose HTML sanitization utilities #3525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/base/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Note: Changes to this file also must be applied to the top level .eslintignore file.
test
lib
overlay
dist
src/thirdparty
bundle.esm.js
Expand Down
1 change: 1 addition & 0 deletions packages/base/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/
overlay/
!core
2 changes: 1 addition & 1 deletion packages/base/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Jo7xX6Xqjqd/+p/wSl0hl57d8ng=
Jo7xX6Xqjqd/+p/wSl0hl57d8ng=
21 changes: 20 additions & 1 deletion packages/base/package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@ const assetParametersScript = resolve.sync("@ui5/webcomponents-base/lib/generate
const serve = resolve.sync("@ui5/webcomponents-tools/lib/serve/index.js");
const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/index.js");
const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;

const scripts = {
clean: "rimraf dist && rimraf .port",
lint: "eslint . --config config/.eslintrc.js",
prepare: "nps clean copy generateAssetParameters",
prepare: "nps clean integrate copy generateAssetParameters",
integrate: {
default: "nps integrate.copy-used-modules integrate.copy-overlay integrate.replace-amd integrate.replace-export-true integrate.replace-export-false integrate.amd-to-es6 integrate.replace-global-core-usage integrate.esm-abs-to-rel integrate.third-party",
"copy-used-modules": `node ${copyUsedModules} ./used-modules.txt dist/`,
"copy-overlay": `copy-and-watch "overlay/**/*.js" dist/`,
"replace-amd": "replace-in-file sap.ui.define define dist/**/*.js",
"replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
"replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
"amd-to-es6": "amdtoes6 --src=dist/ --replace --glob=**/*.js",
"replace-global-core-usage": `node ${replaceGlobalCore} dist/`,
"esm-abs-to-rel": `node ${esmAbsToRel} dist/ dist/`,
"third-party": {
default: "nps integrate.third-party.copy integrate.third-party.fix",
copy: "mkdirp dist/sap/ui/thirdparty/ && copy-and-watch ../../node_modules/@openui5/sap.ui.core/src/sap/ui/thirdparty/caja-html-sanitizer.js dist/sap/ui/thirdparty/",
fix: "replace-in-file 240 xA0 dist/sap/ui/thirdparty/caja-html-sanitizer.js"
},
},
build: {
default: `${UP_TO_DATE} || nps lint prepare build.bundle hash`,
bundle: "rollup --config config/rollup.config.js",
Expand Down
5 changes: 4 additions & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
},
"devDependencies": {
"@ui5/webcomponents-tools": "1.0.0-rc.14",
"@buxlabs/amd-to-es6": "0.16.0",
"@openui5/sap.ui.core": "1.87.3",
"array-uniq": "^2.0.0",
"chromedriver": "92.0.0",
"copy-and-watch": "^0.1.5",
"eslint": "^7.22.0",
"eslint-config-airbnb-base": "^14.2.1",
"npm-run-all": "^4.1.5",
"path-exists-cli": "^1.0.0"
"path-exists-cli": "^1.0.0",
"replace-in-file": "^6.2.0"
}
}
7 changes: 7 additions & 0 deletions packages/base/src/util/HTMLSanitizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sanitizeHTML from "../sap/base/security/sanitizeHTML.js";
import URLListValidator from "../sap/base/security/URLListValidator.js";

export {
URLListValidator,
sanitizeHTML,
};
7 changes: 7 additions & 0 deletions packages/base/used-modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Needed files from OpenUI5

sap/base/util/now.js
sap/base/Log.js
sap/base/assert.js
sap/base/security/URLListValidator.js
sap/base/security/sanitizeHTML.js
9 changes: 6 additions & 3 deletions packages/localization/package-scripts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const resolve = require("resolve");
const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
const copyUsedModules = resolve.sync("@ui5/webcomponents-tools/lib/copy-list/index.js");
const replaceGlobalCore = resolve.sync("@ui5/webcomponents-tools/lib/replace-global-core/index.js");
const esmAbsToRel = resolve.sync("@ui5/webcomponents-tools/lib/esm-abs-to-rel/index.js");
const UP_TO_DATE = `node ${hashIsUpToDate} dist/ hash.txt && echo "Up to date."`;

const scripts = {
Expand All @@ -13,12 +16,12 @@ const scripts = {
"replace-export-true": `replace-in-file ", /* bExport= */ true" "" dist/**/*.js`,
"replace-export-false": `replace-in-file ", /* bExport= */ false" "" dist/**/*.js`,
"amd-to-es6": "amdtoes6 --src=dist --replace --glob=**/*.js",
"replace-global-core-usage": "node ./lib/replace-global-core/index.js dist/",
"esm-abs-to-rel": "node ./lib/esm-abs-to-rel/index.js dist/",
"replace-global-core-usage": `node ${replaceGlobalCore} dist/`,
"esm-abs-to-rel": `node ${esmAbsToRel} dist/`,
jsonImports: "node ./lib/generate-json-imports/cldr.js"
},
copy: {
"used-modules": "node ./lib/copy-list/index.js ./used-modules.txt dist/",
"used-modules": `node ${copyUsedModules} ./used-modules.txt dist/`,
cldr: `copy-and-watch "../../node_modules/@openui5/sap.ui.core/src/sap/ui/core/cldr/*.json" dist/generated/assets/cldr/`,
overlay: `copy-and-watch "overlay/**/*.js" dist/`,
src: `copy-and-watch "src/**/*.js" dist/`,
Expand Down
4 changes: 4 additions & 0 deletions packages/main/bundle.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
window.isIE = isIE; // attached to the window object for testing purposes

import { sanitizeHTML, URLListValidator } from "@ui5/webcomponents-base/dist/util/HTMLSanitizer.js";
window.sanitizeHTML = sanitizeHTML;
window.URLListValidator = URLListValidator;

import { getAnimationMode, setAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
import { getTheme, setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
import { getLanguage, setLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
Expand Down
1 change: 1 addition & 0 deletions packages/theme-base/css-vars-usage.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"--sapButton_Attention_BorderColor",
"--sapButton_Attention_Hover_Background",
"--sapButton_Attention_Hover_BorderColor",
"--sapButton_Attention_Hover_TextColor",
"--sapButton_Attention_TextColor",
"--sapButton_Background",
"--sapButton_BorderColor",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"

"@buxlabs/amd-to-es6@^0.16.0":
"@buxlabs/amd-to-es6@0.16.0", "@buxlabs/amd-to-es6@^0.16.0":
version "0.16.0"
resolved "https://registry.yarnpkg.com/@buxlabs/amd-to-es6/-/amd-to-es6-0.16.0.tgz#172a4fc04ffe033e96c67b5b897e83d59d8377b5"
integrity sha512-6wTVkChKcbWcg4Kio61j9HnT7SWMBVbv+y7pu96RvpoMyM/qF/th7x8SqTavnEhLfFjeJPG51fthSdRurGKpsQ==
Expand Down