Skip to content

Commit a3880ac

Browse files
fix(ui): replace ES6/ES2021 features with ES5 equivalents for IE compatibility
Resolves #53. The testsuiteutils.js file used const, String.prototype.endsWith(), String.prototype.includes(), String.prototype.replaceAll(), and XMLHttpRequest.DONE which are all unsupported in Internet Explorer. Changes: - const -> var (all declarations are never reassigned) - endsWith() -> indexOf() polyfill pattern - includes() -> indexOf() !== -1 - Native .replaceAll() -> existing replaceAll() helper (lines 57-63) - XMLHttpRequest.DONE -> 4 (the spec constant value) No behavioral change in modern browsers. No other files modified.
1 parent b7b159c commit a3880ac

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

src/main/webapp/js/testsuiteutils.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ $(document).ready(function() {
1414
});
1515

1616
function dispatchToSubmit(event) {
17-
const id = event.target.id;
18-
const button = document.getElementById(id);
19-
const methodName = button.getAttribute('method');
20-
const testcase = button.getAttribute('testcase');
17+
var id = event.target.id;
18+
var button = document.getElementById(id);
19+
var methodName = button.getAttribute('method');
20+
var testcase = button.getAttribute('testcase');
2121
switch (methodName) {
2222
case 'submitHeaderForm':
2323
submitHeaderForm(testcase);
@@ -41,12 +41,12 @@ function dispatchToSubmit(event) {
4141

4242
// Generate custom cookie in browser for testing purposes
4343
function setCookie(event) {
44-
const id = event.target.id;
45-
const button = document.getElementById(id);
46-
const testcase = button.getAttribute('testcase');
47-
const cvalue = document.getElementById(testcase + 'A').value;
44+
var id = event.target.id;
45+
var button = document.getElementById(id);
46+
var testcase = button.getAttribute('testcase');
47+
var cvalue = document.getElementById(testcase + 'A').value;
4848

49-
const formVar = "#Form" + testcase;
49+
var formVar = "#Form" + testcase;
5050
var URL = $(formVar).attr("action");
5151

5252
Cookies.set(testcase, cvalue, {
@@ -63,10 +63,10 @@ function replaceAll(str, find, replace) {
6363
}
6464

6565
function submitHeaderForm(testcase) {
66-
const formVar = "#Form" + testcase;
67-
const suffix = "-Unsafe";
66+
var formVar = "#Form" + testcase;
67+
var suffix = "-Unsafe";
6868
var rawtestcase = testcase;
69-
if (testcase.endsWith(suffix)) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
69+
if (testcase.indexOf(suffix, testcase.length - suffix.length) !== -1) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
7070
var formData = $(formVar).serialize();
7171
var URL = $(formVar).attr("action");
7272
var text = $(formVar + " input[id=" + rawtestcase + "]").val();
@@ -77,8 +77,8 @@ function submitHeaderForm(testcase) {
7777
xhr.setRequestHeader( rawtestcase, text );
7878

7979
xhr.onreadystatechange = function () {
80-
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
81-
if (URL.includes("xss")) {
80+
if (xhr.readyState == 4 && xhr.status == 200) {
81+
if (URL.indexOf("xss") !== -1) {
8282
$("#code").html(stripHTML(xhr.responseText));
8383
} else { $("#code").text(decodeEscapeSequence(stripHTML(xhr.responseText))); }
8484
} else {
@@ -89,10 +89,10 @@ function submitHeaderForm(testcase) {
8989
}
9090

9191
function submitHeaderNamesForm(testcase) {
92-
const formVar = "#Form" + testcase;
93-
const suffix = "-Unsafe";
92+
var formVar = "#Form" + testcase;
93+
var suffix = "-Unsafe";
9494
var rawtestcase = testcase;
95-
if (testcase.endsWith(suffix)) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
95+
if (testcase.indexOf(suffix, testcase.length - suffix.length) !== -1) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
9696
var formData = $(formVar).serialize();
9797
var URL = $(formVar).attr("action");
9898
var text = $(formVar + " input[id=" + rawtestcase + "]").val();
@@ -103,7 +103,7 @@ function submitHeaderNamesForm(testcase) {
103103
xhr.setRequestHeader( text, rawtestcase );
104104

105105
xhr.onreadystatechange = function () {
106-
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
106+
if (xhr.readyState == 4 && xhr.status == 200) {
107107
$("#code").text(decodeEscapeSequence(stripHTML(xhr.responseText)));
108108
} else {
109109
$("#code").text("Error " + xhr.status + " " + xhr.statusText + " occurred.");
@@ -113,10 +113,10 @@ function submitHeaderNamesForm(testcase) {
113113
}
114114

115115
function submitParameterNamesForm(testcase) {
116-
const formVar = "#Form" + testcase;
117-
const suffix = "-Unsafe";
116+
var formVar = "#Form" + testcase;
117+
var suffix = "-Unsafe";
118118
var rawtestcase = testcase;
119-
if (testcase.endsWith(suffix)) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
119+
if (testcase.indexOf(suffix, testcase.length - suffix.length) !== -1) rawtestcase = testcase.substring(0, testcase.length - suffix.length);
120120
var text = $(formVar + " input[id=" + rawtestcase + "]").val();
121121

122122
// This block not in submitFormAttack() - why?
@@ -135,8 +135,8 @@ function submitParameterNamesForm(testcase) {
135135
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
136136

137137
xhr.onreadystatechange = function () {
138-
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
139-
if (URL.includes("xss")) {
138+
if (xhr.readyState == 4 && xhr.status == 200) {
139+
if (URL.indexOf("xss") !== -1) {
140140
$("#code").html(xhr.responseText);
141141
} else { $("#code").text(decodeEscapeSequence(xhr.responseText)); }
142142
} else {
@@ -161,14 +161,14 @@ function stripHTML(xmlResponse) {
161161
if (pIndex > 0) {
162162
result = xmlResponse.substring(pIndex + 4, xmlResponse.length);
163163
}
164-
result = result.replaceAll("<br>", "\n"); // Replace all <br>'s with carriage returns'
164+
result = replaceAll(result, "<br>", "\n"); // Replace all <br>'s with carriage returns'
165165

166166
return result;
167167
}
168168

169169
// XML Ajax Method
170170
function submitXMLwAjax(testcase) {
171-
const formVar = "#Form" + testcase;
171+
var formVar = "#Form" + testcase;
172172
var URL = $(formVar).attr("action");
173173
var dataF = "<person>";
174174
$(formVar + " input[type=text]").each(function() {
@@ -193,9 +193,11 @@ function submitXMLwAjax(testcase) {
193193

194194
function getXMLMsgValues(xmlResponse) {
195195
// Crude: Rips out XML content we don't want to display in the browser'
196-
var result = xmlResponse.replaceAll('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', "");
197-
result = result.replaceAll("<xMLMessages>","").replaceAll("</xMLMessages>","").replaceAll("<message><msg>","");
198-
result = result.replaceAll("</msg></message>","\n");
196+
var result = replaceAll(xmlResponse, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', "");
197+
result = replaceAll(result, "<xMLMessages>", "");
198+
result = replaceAll(result, "</xMLMessages>", "");
199+
result = replaceAll(result, "<message><msg>", "");
200+
result = replaceAll(result, "</msg></message>", "\n");
199201

200202
return result;
201203
}
@@ -222,7 +224,7 @@ function getXMLMsgValues(xmlResponse) {
222224

223225
function submitJSONwAjax(testcase) {
224226

225-
const formVar = "#Form" + testcase;
227+
var formVar = "#Form" + testcase;
226228
var dataF = $(formVar).serializeFormJSON();
227229
var URL = $(formVar).attr("action");
228230

@@ -242,10 +244,10 @@ function submitJSONwAjax(testcase) {
242244
function getJsonMsgValues(jsonResponse) {
243245
var result = "";
244246
JSON.parse(jsonResponse).forEach(function (msg) {
245-
const prefix = '{"msg":"';
247+
var prefix = '{"msg":"';
246248
var msgString = JSON.stringify(msg); // e.g., {"msg":"Here is the standard output of the command:"}
247249
// FIXME: This is a hack. There has to be a better/more native way in JavaScript
248-
msgString = msgString.substring(prefix.length, msgString.length - 2).replaceAll("\\n", "\n");
250+
msgString = replaceAll(msgString.substring(prefix.length, msgString.length - 2), "\\n", "\n");
249251
result += msgString + "\n";
250252
});
251253

0 commit comments

Comments
 (0)