taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 054d62aeaccee74854a881a774cefa034e9a0b59
parent 02645c38b2eb81bbf43013c377d44a09717f4279
Author: Florian Dold <dold@taler.net>
Date:   Mon, 20 Jul 2026 20:43:16 +0200

util: fix scheme detection and error stringification

canonicalizeBaseUrl tested for the letters "http" rather than for a scheme,
so "httpbin.org" was passed to new URL() unprefixed.  stringifyError called
toString() unguarded, which throws for a null-prototype object.

Diffstat:
Mpackages/taler-util/src/helpers.ts | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/packages/taler-util/src/helpers.ts b/packages/taler-util/src/helpers.ts @@ -29,7 +29,9 @@ import { URL } from "./url.js"; * See http://api.taler.net/wallet.html#general */ export function canonicalizeBaseUrl(url: string): string { - if (!url.startsWith("http") && !url.startsWith("https")) { + // Test for a scheme, not for the letters "http": "httpbin.org" starts + // with them but still needs one prepended. + if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) { url = "https://" + url; } const x = new URL(url); @@ -121,7 +123,13 @@ export function stringifyError(x: any): string { return `<thrown null>`; } if (typeof x === "object") { - return x.toString(); + // A null-prototype object has no toString, and throwing here would + // replace the diagnostic with a crash. + try { + return String(x); + } catch (e) { + return Object.prototype.toString.call(x); + } } return `<thrown ${typeof x}>`; }