]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
Add polyfill for String.prototype.trim in vpnc-script-win.js
authorDaniel Lenski <dlenski@gmail.com>
Wed, 22 Sep 2021 19:12:00 +0000 (19:12 +0000)
committerDaniel Lenski <dlenski@gmail.com>
Wed, 22 Sep 2021 19:12:00 +0000 (19:12 +0000)
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 <dlenski@gmail.com>
vpnc-script-win.js

index 56f85edf07cd76de8992dd82edac552048dc3639..3e8043a3c92bd916b13eddd3b92bbda71e654f04 100644 (file)
@@ -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
 // --------------------------------------------------------------