From: Daniel Lenski Date: Wed, 22 Sep 2021 19:12:00 +0000 (+0000) Subject: Add polyfill for String.prototype.trim in vpnc-script-win.js X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6aa36580e1f31d81b6be3f6da7a4d28c260de392;p=users%2Fdwmw2%2Fvpnc-scripts.git Add polyfill for String.prototype.trim in vpnc-script-win.js As noted in https://gitlab.com/openconnect/openconnect/-/issues/312#note_684460541, Windows Scripting Host's "JScript" does not appear to support the `String.prototype.trim` method, apparently due to being based on a very old ECMAScript standard. The straightforward solution is to use the JavaScript polyfill described in https://stackoverflow.com/a/35456830. Signed-off-by: Daniel Lenski --- diff --git a/vpnc-script-win.js b/vpnc-script-win.js index 56f85ed..3e8043a 100644 --- a/vpnc-script-win.js +++ b/vpnc-script-win.js @@ -51,6 +51,12 @@ function getDefaultGateway() return (""); } +if (!String.prototype.trim) { + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; +} + // -------------------------------------------------------------- // Script starts here // --------------------------------------------------------------