Skip to content

Commit 937aee1

Browse files
pteroca-comksroga
andauthored
Escape values in egg manager (#81)
Co-authored-by: Konrad Sroga <[email protected]>
1 parent 734ca86 commit 937aee1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

themes/default/components/egg_manager.html.twig

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@
245245
return table.outerHTML;
246246
}
247247
248+
function escAttr(s) {
249+
return String(s ?? '')
250+
.replaceAll('&', '&amp;')
251+
.replaceAll('"', '&quot;')
252+
.replaceAll("'", '&#39;')
253+
.replaceAll('<', '&lt;')
254+
.replaceAll('>', '&gt;');
255+
}
256+
248257
function getInputName(eggId, variableId, name) {
249258
let inputName = `eggs_configuration[${eggId}]`;
250259
if (variableId && isNaN(variableId) === false) {
@@ -260,7 +269,8 @@
260269
if (options) {
261270
return createSelect(value, eggId, options, name);
262271
}
263-
return `<input type="text" value="${value}" name="${getInputName(eggId, variableId || 'startup', name)}" class="form-control" onchange="saveEggsConfigurationToHiddenField()">`;
272+
const v = escAttr(value);
273+
return `<input type="text" value="${v}" name="${getInputName(eggId, variableId || 'startup', name)}" class="form-control" onchange="saveEggsConfigurationToHiddenField()">`;
264274
}
265275
266276
function createCheckbox(checked, eggId, variableId, name) {
@@ -277,11 +287,13 @@
277287
function createSelect(value, eggId, options, name) {
278288
let select = `<select name="${getInputName(eggId, 'docker_image', name)}" class="form-control" style="font-size: 14px;" onchange="saveEggsConfigurationToHiddenField()">`;
279289
for (const [key, option] of Object.entries(options)) {
280-
select += `<option value="${option}" ${value === key ? 'selected' : ''}>${option}</option>`;
290+
const optVal = escAttr(option);
291+
const selected = (value === key) ? 'selected' : '';
292+
select += `<option value="${optVal}" ${selected}>${optVal}</option>`;
281293
}
282294
select += '</select>';
283295
return select;
284-
}
296+
}
285297
286298
function hasSlotPrices() {
287299
let slotPricesContainer = document.querySelector('#Product_slotPrices');

0 commit comments

Comments
 (0)