Skip to content

Fix version.js JScript runtime error under Windows Script Host (cscript)#1505

Open
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/fix-version-js-jscript-trim
Open

Fix version.js JScript runtime error under Windows Script Host (cscript)#1505
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/fix-version-js-jscript-trim

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Problem

Every Windows CI build logs:

tools/version.js(48, 3) Microsoft JScript runtime error: Object doesn't support this property or method

version.js is executed by the Windows Script Host JScript engine (cscript). #1455 replaced ver1.replace("\n", "") with ver1.trim() to satisfy CodeQL js/incomplete-sanitization, but the WSH JScript engine does not implement String.prototype.trim(), so the script throws at line 48.

Fix

Replace .trim() with an ES3-compatible global-anchored regex:

ver1 = ver1.replace(/^\s+|\s+$/g, "");

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.js now exits 0 and regenerates Version.hpp / version.txt.
  • Confirmed the same engine rejects .trim() with the exact CI error (Object doesn't support property or method 'trim').

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>
@bmehta001 bmehta001 requested a review from a team as a code owner July 10, 2026 22:24
@bmehta001 bmehta001 requested a review from Copilot July 10, 2026 22:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants