Fix version.js JScript runtime error under Windows Script Host (cscript)#1505
Open
bmehta001 wants to merge 1 commit into
Open
Fix version.js JScript runtime error under Windows Script Host (cscript)#1505bmehta001 wants to merge 1 commit into
bmehta001 wants to merge 1 commit into
Conversation
String.prototype.trim() (added in microsoft#1455 to complete the newline sanitization) is not implemented by the Windows Script Host JScript engine that runs version.js via cscript, so every Windows CI build logged 'version.js(48,3) Microsoft JScript runtime error: Object doesn't support this property or method'. Replace trim() with an ES3-compatible global-anchored regex that strips leading/trailing whitespace (including all trailing newlines), so the script runs cleanly while keeping the complete-sanitization behavior CodeQL asked for. Verified: 'cscript //nologo version.js' now exits 0 and regenerates Version.hpp; confirmed the JScript engine rejects .trim() with the same error seen in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Windows CI/runtime failure when tools/version.js is executed by Windows Script Host’s JScript engine (cscript), which does not implement String.prototype.trim().
Changes:
- Replace the ES5
ver1.trim()call with an ES3-compatible whitespace-strip using a regex (ver1.replace(/^\s+|\s+$/g, "")). - Add an explanatory comment describing the JScript compatibility constraint and the intent to fully remove trailing newlines/whitespace.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
Every Windows CI build logs:
version.jsis executed by the Windows Script Host JScript engine (cscript). #1455 replacedver1.replace("\n", "")withver1.trim()to satisfy CodeQLjs/incomplete-sanitization, but the WSH JScript engine does not implementString.prototype.trim(), so the script throws at line 48.Fix
Replace
.trim()with an ES3-compatible global-anchored regex:This strips leading/trailing whitespace (including all trailing newlines), so it keeps the complete-sanitization behavior CodeQL asked for while running under the JScript engine.
Validation
cscript //nologo version.jsnow exits 0 and regeneratesVersion.hpp/version.txt..trim()with the exact CI error (Object doesn't support property or method 'trim').