[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 01/02: check conversion URL
From: |
gnunet |
Subject: |
[taler-wallet-core] 01/02: check conversion URL |
Date: |
Thu, 30 Nov 2023 15:09:03 +0100 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository wallet-core.
commit d5a46a3bc4025d9c2abd2d73831bf033272f174d
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Nov 30 10:30:32 2023 -0300
check conversion URL
---
packages/taler-util/src/codec.ts | 33 +++++++++++++++++++++++++++++++++
packages/taler-util/src/taler-types.ts | 3 ++-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/codec.ts b/packages/taler-util/src/codec.ts
index 695f3c147..670111b75 100644
--- a/packages/taler-util/src/codec.ts
+++ b/packages/taler-util/src/codec.ts
@@ -321,6 +321,39 @@ export function codecForString(): Codec<string> {
};
}
+/**
+ * Return a codec for a value that must be a string.
+ */
+export function codecForStringURL(shouldEndWithSlash?: boolean): Codec<string>
{
+ return {
+ decode(x: any, c?: Context): string {
+ if (typeof x !== "string") {
+ throw new DecodingError(
+ `expected string at ${renderContext(c)} but got ${typeof x}`,
+ );
+ }
+ if (shouldEndWithSlash && !x.endsWith("/")) {
+ throw new DecodingError(
+ `expected URL string that ends with slash at ${renderContext(c)} but
got ${x}`,
+ );
+ }
+ try {
+ const url = new URL(x)
+ return x;
+ } catch(e) {
+ if (e instanceof Error) {
+ throw new DecodingError(e.message)
+ } else {
+ throw new DecodingError(
+ `expected an URL string at ${renderContext(c)} but got "${x}"`,
+ );
+ }
+
+ }
+ },
+ };
+}
+
/**
* Codec that allows any value.
*/
diff --git a/packages/taler-util/src/taler-types.ts
b/packages/taler-util/src/taler-types.ts
index e32c5a99d..3b96c52fe 100644
--- a/packages/taler-util/src/taler-types.ts
+++ b/packages/taler-util/src/taler-types.ts
@@ -38,6 +38,7 @@ import {
codecForMap,
codecForNumber,
codecForString,
+ codecForStringURL,
codecOptional,
} from "./codec.js";
import { strcmp } from "./helpers.js";
@@ -2372,7 +2373,7 @@ export interface ExchangeWireAccount {
export const codecForExchangeWireAccount = (): Codec<ExchangeWireAccount> =>
buildCodecForObject<ExchangeWireAccount>()
- .property("conversion_url", codecOptional(codecForString()))
+ .property("conversion_url", codecOptional(codecForStringURL()))
.property("credit_restrictions", codecForList(codecForAny()))
.property("debit_restrictions", codecForList(codecForAny()))
.property("master_sig", codecForString())
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.