fix(ui): replace ES6/ES2021 features with ES5 equivalents for IE compatibility#447
Conversation
…atibility Resolves OWASP-Benchmark#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.
|
Is this PR really neccessary? Internet Explorer was discontinued years ago. |
I'm completely the wrong person to ask haha. I'd say the value is fairly minor, probably edge cases like legacy enterprise that are locked down, i.e banks. |
|
@davewichers what's your opinion about this? |
|
@darkspirit510 - I don't have a strong opinion here. I'm OK with merging it in if it really fixes the issue and doesn't break anything with current browsers. This is kind of a minor issue. |
Summary
Fixes #53 -- JavaScript in
testsuiteutils.jsuses ES6 and ES2021 features that are unsupported in Internet Explorer, causing all AJAX-based test case submissions to fail when accessing Benchmark from IE.Single file changed:
src/main/webapp/js/testsuiteutils.js(33 insertions, 31 deletions)No Java files, HTML files, config files, or test cases were modified.
Root Cause
Five categories of IE-incompatible JavaScript features were identified in
testsuiteutils.js:constkeywordString.prototype.endsWith()TypeErrorin all IE versions (ES6, not implemented)String.prototype.includes()TypeErrorin all IE versions (ES6, not implemented)String.prototype.replaceAll()TypeErrorin all IE versions (ES2021, not implemented)XMLHttpRequest.DONEundefinedin IE 8/9These cause
TypeErrorexceptions that prevent all five submission methods (submitHeaderForm,submitHeaderNamesForm,submitParameterNamesForm,submitJSONwAjax,submitXMLwAjax) from functioning in IE.Changes
1.
const->varAll 13
constdeclarations were changed tovar. Every declaration is a simple assignment that is never reassigned, and all are at function scope (not inside blocks), so there is no behavioral difference.2.
endsWith()->indexOf()polyfillStandard MDN-recommended polyfill pattern. Applied in
submitHeaderForm,submitHeaderNamesForm, andsubmitParameterNamesForm.3.
includes()->indexOf()Direct ES5 equivalent. Applied in
submitHeaderFormandsubmitParameterNamesForm.4. Native
.replaceAll()-> existing helper functionThe file already contained an unused helper pair at lines 57-63:
This helper was presumably the original IE-compatible implementation. The native
String.prototype.replaceAll()method calls were converted to use this existing helper instead:The chained call on line 197 was broken into separate statements for readability:
All search strings are fixed literals (no user input), and all replacement strings contain no
$special patterns, so the helper produces identical results to the native method.5.
XMLHttpRequest.DONE->4The numeric constant
4is the spec-defined value ofXMLHttpRequest.DONE. Applied in threeonreadystatechangehandlers.What Was NOT Changed
src/main/java/org/owasp/benchmark/testcode/-- all 2,740 test case Java files are untouchedsrc/main/webapp/{category}-{NN}/*.html-- all 2,741 test case HTML pages are untouchedjquery.min.js(v2.1.4) andjs.cookie.js(v2.1.3) -- vendor libraries, already IE-compatibleHTTPResponseHeaderFilter.java-- CSP header uses'self'which is origin-relative and works correctly for both localhost and remote IP accessRegression Risk
Zero. Every replacement is a mechanical downlevel from ES6/ES2021 to ES5 with functionally identical behavior:
varforconston non-reassigned bindings at function scope -- identical semanticsindexOf()polyfills forendsWith()/includes()-- standard, well-tested patternsreplaceAll()uses regex with escaped special characters -- produces identical output to nativeString.prototype.replaceAll()for all 8 call sites (verified: regex escaping handles?,.,=,/,\correctly in all search strings; no$patterns in any replacement strings)4 === XMLHttpRequest.DONEby spec definitionModern browsers (Chrome, Firefox, Edge, Safari) will behave exactly as before. IE 9+ will now also function correctly.
Test Plan
git diff --statshows onlytestsuiteutils.jschangedconst,let,.endsWith(,.includes(,.replaceAll(, orXMLHttpRequest.DONEpatterns remain in the filerunBenchmark.sh-- verify test case pages load and AJAX submissions work in a modern browserrunRemoteAccessibleBenchmark.shvia remote IP access