diff --git a/src/core/operations/ShowBase64Offsets.mjs b/src/core/operations/ShowBase64Offsets.mjs
index 37d8a6ce..a375d7db 100644
--- a/src/core/operations/ShowBase64Offsets.mjs
+++ b/src/core/operations/ShowBase64Offsets.mjs
@@ -77,84 +77,84 @@ class ShowBase64Offsets extends Operation {
staticSection = offset0.slice(0, -3);
offset0 = "" +
- staticSection + "" +
- "" + offset0.substr(offset0.length - 3, 1) + "" +
- "" + offset0.substr(offset0.length - 2) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset0.substr(offset0.length - 3, 1)) + "" +
+ "" + Utils.escapeHtml(offset0.substr(offset0.length - 2)) + "";
} else if (len0 % 4 === 3) {
staticSection = offset0.slice(0, -2);
offset0 = "" +
- staticSection + "" +
- "" + offset0.substr(offset0.length - 2, 1) + "" +
- "" + offset0.substr(offset0.length - 1) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset0.substr(offset0.length - 2, 1)) + "" +
+ "" + Utils.escapeHtml(offset0.substr(offset0.length - 1)) + "";
} else {
staticSection = offset0;
offset0 = "" +
- staticSection + "";
+ Utils.escapeHtml(staticSection) + "";
}
if (!showVariable) {
- offset0 = staticSection;
+ offset0 = Utils.escapeHtml(staticSection);
}
// Highlight offset 1
- padding = "" + offset1.substr(0, 1) + "" +
- "" + offset1.substr(1, 1) + "";
+ padding = "" + Utils.escapeHtml(offset1.substr(0, 1)) + "" +
+ "" + Utils.escapeHtml(offset1.substr(1, 1)) + "";
offset1 = offset1.substr(2);
if (len1 % 4 === 2) {
staticSection = offset1.slice(0, -3);
offset1 = padding + "" +
- staticSection + "" +
- "" + offset1.substr(offset1.length - 3, 1) + "" +
- "" + offset1.substr(offset1.length - 2) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset1.substr(offset1.length - 3, 1)) + "" +
+ "" + Utils.escapeHtml(offset1.substr(offset1.length - 2)) + "";
} else if (len1 % 4 === 3) {
staticSection = offset1.slice(0, -2);
offset1 = padding + "" +
- staticSection + "" +
- "" + offset1.substr(offset1.length - 2, 1) + "" +
- "" + offset1.substr(offset1.length - 1) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset1.substr(offset1.length - 2, 1)) + "" +
+ "" + Utils.escapeHtml(offset1.substr(offset1.length - 1)) + "";
} else {
staticSection = offset1;
offset1 = padding + "" +
- staticSection + "";
+ Utils.escapeHtml(staticSection) + "";
}
if (!showVariable) {
- offset1 = staticSection;
+ offset1 = Utils.escapeHtml(staticSection);
}
// Highlight offset 2
- padding = "" + offset2.substr(0, 2) + "" +
- "" + offset2.substr(2, 1) + "";
+ padding = "" + Utils.escapeHtml(offset2.substr(0, 2)) + "" +
+ "" + Utils.escapeHtml(offset2.substr(2, 1)) + "";
offset2 = offset2.substr(3);
if (len2 % 4 === 2) {
staticSection = offset2.slice(0, -3);
offset2 = padding + "" +
- staticSection + "" +
- "" + offset2.substr(offset2.length - 3, 1) + "" +
- "" + offset2.substr(offset2.length - 2) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset2.substr(offset2.length - 3, 1)) + "" +
+ "" + Utils.escapeHtml(offset2.substr(offset2.length - 2)) + "";
} else if (len2 % 4 === 3) {
staticSection = offset2.slice(0, -2);
offset2 = padding + "" +
- staticSection + "" +
- "" + offset2.substr(offset2.length - 2, 1) + "" +
- "" + offset2.substr(offset2.length - 1) + "";
+ Utils.escapeHtml(staticSection) + "" +
+ "" + Utils.escapeHtml(offset2.substr(offset2.length - 2, 1)) + "" +
+ "" + Utils.escapeHtml(offset2.substr(offset2.length - 1)) + "";
} else {
staticSection = offset2;
offset2 = padding + "" +
- staticSection + "";
+ Utils.escapeHtml(staticSection) + "";
}
if (!showVariable) {
- offset2 = staticSection;
+ offset2 = Utils.escapeHtml(staticSection);
}
return (showVariable ? "Characters highlighted in green could change if the input is surrounded by more data." +
diff --git a/tests/operations/tests/Base64.mjs b/tests/operations/tests/Base64.mjs
index 6e6fa703..5dca403a 100644
--- a/tests/operations/tests/Base64.mjs
+++ b/tests/operations/tests/Base64.mjs
@@ -116,4 +116,15 @@ TestRegister.addTests([
},
],
},
+ {
+ name: "Show Base64 offsets: escapes static output",
+ input: "\x00\x10\x83\x10\x51\x87",
+ expectedOutput: "<script>\n<AQmsBRk66\n<ia1AEIM6",
+ recipeConfig: [
+ {
+ op: "Show Base64 offsets",
+ args: ["