Content-Length: 409509 | pFad | http://github.com/namecheap/ilc/pull/331/files/1bd3241f0f32c86081926cf9a4794cc1bb2864ed

DF Fix using script tag in custom html by nightnei · Pull Request #331 · namecheap/ilc · GitHub
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
Changes from 4 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 () {
@@ -12,6 +14,11 @@ export default function () {

registryConf = JSON.parse(confScript.innerHTML);

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

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

return registryConf;
5 changes: 5 additions & 0 deletions ilc/common/utils.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -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,
});

35 changes: 35 additions & 0 deletions ilc/server/tailor/configs-injector.spec.js
Original file line number Diff line number Diff line change
@@ -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'] = {
@@ -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;'
}
}
});
};

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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/namecheap/ilc/pull/331/files/1bd3241f0f32c86081926cf9a4794cc1bb2864ed

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy