fix(ui): replace ES6/ES2021 features with ES5 equivalents for IE compatibility#447
Open
TheAuditorTool wants to merge 1 commit intoOWASP-Benchmark:masterfrom
Open
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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