gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant-backoffice] branch master updated: payto regex


From: gnunet
Subject: [taler-merchant-backoffice] branch master updated: payto regex
Date: Fri, 12 Feb 2021 05:36:48 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository merchant-backoffice.

The following commit(s) were added to refs/heads/master by this push:
     new 4577c84  payto regex
4577c84 is described below

commit 4577c84b9f552315f131b58631490d0e76e8559a
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Feb 12 01:36:36 2021 -0300

    payto regex
---
 src/constants.ts                     |  2 ++
 src/i18n/index.ts                    |  6 ++++--
 src/routes/instances/UpdateModal.tsx |  4 +++-
 tests/functions/regex.test.ts        | 25 +++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/constants.ts b/src/constants.ts
new file mode 100644
index 0000000..fec7f7c
--- /dev/null
+++ b/src/constants.ts
@@ -0,0 +1,2 @@
+export const 
PAYTO_REGEX=/^payto:\/\/[a-zA-Z][a-zA-Z0-9-.]*(\/[a-zA-Z0-9\-\.\~\(\)@_%:!$&'*+,;=]*)*\??((amount|receiver-name|sender-name|instruction|message)=[a-zA-Z0-9\-\.\~\(\)@_%:!$'*+,;=]*&?)*$/
+
diff --git a/src/i18n/index.ts b/src/i18n/index.ts
index 24851cb..9cb060d 100644
--- a/src/i18n/index.ts
+++ b/src/i18n/index.ts
@@ -70,7 +70,8 @@ export default {
     },
     validation: {
       required: '{{label}} es obligatorio',
-      typeError: '{{label}} '
+      typeError: '{{label}}',
+      payto: 'la dirección de pago no es valida',
     },
     text: {
       instances: 'Instancias',
@@ -152,7 +153,8 @@ export default {
     },
     validation: {
       required: '{{label}} is required',
-      typeError: '{{label}} '
+      typeError: '{{label}}',
+      payto: 'the pay address is not valid',
     },
     text: {
       instances: 'Instances',
diff --git a/src/routes/instances/UpdateModal.tsx 
b/src/routes/instances/UpdateModal.tsx
index 934d6f4..9fc1309 100644
--- a/src/routes/instances/UpdateModal.tsx
+++ b/src/routes/instances/UpdateModal.tsx
@@ -4,6 +4,7 @@ import { MerchantBackend } from "../../declaration";
 import * as yup from 'yup';
 import ConfirmModal from '../../components/modal'
 import YupInput from "../../components/yup/YupInput";
+import { PAYTO_REGEX } from "../../constants";
 
 function stringToArray(this: yup.AnySchema, current: any, original: string): 
string[] {
   if (this.isType(current)) return current;
@@ -12,7 +13,8 @@ function stringToArray(this: yup.AnySchema, current: any, 
original: string): str
 
 const schema = yup.object().shape({
   name: yup.string().required(),
-  payto_uris: yup.array().of(yup.string()).min(1).transform(stringToArray),
+  payto_uris: yup.array().of(yup.string()).min(1)
+    .transform(stringToArray).test('payto','{path} is not valid', (values): 
boolean => !!values && values.filter( v => v && PAYTO_REGEX.test(v) ).length > 
0 ),
   default_max_deposit_fee: yup.string().required(),
   default_max_wire_fee: yup.string().required(),
   default_wire_fee_amortization: yup.number().required(),
diff --git a/tests/functions/regex.test.ts b/tests/functions/regex.test.ts
new file mode 100644
index 0000000..2c1d63f
--- /dev/null
+++ b/tests/functions/regex.test.ts
@@ -0,0 +1,25 @@
+import { PAYTO_REGEX } from "../../src/constants";
+
+const valids = [
+  'payto://iban/DE75512108001245126199?amount=EUR:200.0&message=hello',
+  'payto://ach/122000661/1234',
+  'payto://upi/alice@example.com?receiver-name=Alice&amount=INR:200',
+  'payto://void/?amount=EUR:10.5',
+  'payto://ilp/g.acme.bob'
+]
+
+test('should be valid', () => {
+  valids.forEach(v => expect(v).toMatch(PAYTO_REGEX))
+});
+
+const invalids = [
+  'payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello',
+  'payto://ach/122000661 /1234',
+  'payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200',
+  'payto://void/?mount=EUR:10.5',
+  'payto: //ilp/g.acme.bob'
+]
+
+test('should not be valid', () => {
+  invalids.forEach(v => expect(v).not.toMatch(PAYTO_REGEX))
+});

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]