Skip to content
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

Fix using script tag in custom html #331

Merged
merged 5 commits into from
Nov 22, 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
7 changes: 7 additions & 0 deletions ilc/client/ilcConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { decodeHtmlEntities } from '../common/utils';

let registryConf = null;

export default function () {
Expand All @@ -12,6 +14,11 @@ export default function () {

registryConf = JSON.parse(confScript.innerHTML);

const customHTML = registryConf.settings?.globalSpinner.customHTML;
if (customHTML) {
registryConf.settings.globalSpinner.customHTML = decodeHtmlEntities(customHTML);
}

document.head.appendChild(getSystemjsImportmap(registryConf.apps, registryConf.sharedLibs));

return registryConf;
Expand Down
5 changes: 5 additions & 0 deletions ilc/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ function cloneDeep(source) {

const uniqueArray = array => [...new Set(array)];

const encodeHtmlEntities = value => value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
const decodeHtmlEntities = value => value.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"');

module.exports = {
appIdToNameAndSlot,
makeAppId,
cloneDeep,
uniqueArray,
encodeHtmlEntities,
decodeHtmlEntities,
}
20 changes: 17 additions & 3 deletions ilc/server/tailor/configs-injector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const urljoin = require('url-join');
const { uniqueArray } = require('../../common/utils');
const { uniqueArray, encodeHtmlEntities } = require('../../common/utils');

module.exports = class ConfigsInjector {
#newrelic;
Expand Down Expand Up @@ -159,11 +159,25 @@ module.exports = class ConfigsInjector {
registryConfig.apps,
v => _.pick(v, ['spaBundle', 'cssBundle', 'dependencies', 'props', 'kind', 'wrappedWith'])
);
const spaConfig = JSON.stringify({

let settings = registryConfig.settings;
const customHTML = registryConfig.settings?.globalSpinner?.customHTML;

if (customHTML) {
settings = {
...registryConfig.settings,
globalSpinner: {
...registryConfig.settings.globalSpinner,
customHTML: encodeHtmlEntities(customHTML),
}
};
}

let spaConfig = JSON.stringify({
apps,
routes: registryConfig.routes.map(v => _.omit(v, ['routeId'])),
specialRoutes: _.mapValues(registryConfig.specialRoutes, v => _.omit(v, ['routeId'])),
settings: registryConfig.settings,
settings,
sharedLibs: registryConfig.sharedLibs,
});

Expand Down
35 changes: 35 additions & 0 deletions ilc/server/tailor/configs-injector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ describe('configs injector', () => {
},
routes: [],
specialRoutes: {},
settings: {
globalSpinner: {
customHTML:
'<div class="customSpinnerHTML">I am spinner</div>' +
'<style>' +
'.customSpinnerHTML {' +
'position: fixed;' +
'left: 50%;' +
'top: 50%;' +
'z-index: 1000;' +
'}' +
'</style>' +
'<script type="text/javascript">' +
'console.log("Custom spinner JS")' +
'</script>'
,
}
}
};

registryConfig.apps['thirdApp'] = {
Expand Down Expand Up @@ -215,6 +233,23 @@ describe('configs injector', () => {
},
routes: [],
specialRoutes: {},
settings: {
globalSpinner: {
customHTML:
'&lt;div class=&quot;customSpinnerHTML&quot;&gt;I am spinner&lt;/div&gt;'+
'&lt;style&gt;' +
'.customSpinnerHTML {' +
'position: fixed;' +
'left: 50%;' +
'top: 50%;' +
'z-index: 1000;' +
'}' +
'&lt;/style&gt;' +
'&lt;script type=&quot;text/javascript&quot;&gt;' +
'console.log(&quot;Custom spinner JS&quot;)' +
'&lt;/script&gt;'
}
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion registry/client/src/settings/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Input = (props) => {
);
}
default: {
return (<TextInput source="value" fullWidth={true} />);
return (<TextInput multiline source="value" fullWidth={true} />);
}
}
};
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy