From 82c6999ec2ebe572665cc7db4fdb8223cddfc24d Mon Sep 17 00:00:00 2001 From: Raphael Kabo Date: Sun, 26 May 2024 21:07:39 +0100 Subject: Properly validate URLs when editing --- src/util/validation.ts | 30 ++++++++++++++++++++++++++++++ views/partials/eventForm.handlebars | 5 +++-- views/partials/eventGroupForm.handlebars | 5 +++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/util/validation.ts b/src/util/validation.ts index b9a0c8a..a3bea63 100644 --- a/src/util/validation.ts +++ b/src/util/validation.ts @@ -73,6 +73,20 @@ const validateEmail = (email: string) => { return re.test(email); }; +// From https://stackoverflow.com/a/43467144 +const validateUrl = (url: string) => { + if (!url) { + return false; + } + let validUrl; + try { + validUrl = new URL(url); + } catch (_) { + return false; + } + return validUrl.protocol === "http:" || validUrl.protocol === "https:"; +}; + export const validateEventTime = (start: Date, end: Date): Error | boolean => { if (moment(start).isAfter(moment(end))) { return { @@ -195,6 +209,14 @@ export const validateEventData = ( }); } } + if (validatedData.eventURL) { + if (!validateUrl(validatedData.eventURL)) { + errors.push({ + message: "Event link is invalid.", + field: "eventURL", + }); + } + } return { data: validatedData, @@ -226,6 +248,14 @@ export const validateGroupData = ( }); } } + if (groupData.eventGroupURL) { + if (!validateUrl(groupData.eventGroupURL)) { + errors.push({ + message: "Group link is invalid.", + field: "eventGroupURL", + }); + } + } const validatedData: ValidatedEventGroupData = { ...groupData, diff --git a/views/partials/eventForm.handlebars b/views/partials/eventForm.handlebars index 161f44b..6fbbbf0 100755 --- a/views/partials/eventForm.handlebars +++ b/views/partials/eventForm.handlebars @@ -39,7 +39,8 @@
- + + For tickets or another event page (optional).
@@ -106,7 +107,7 @@ +
+ {{/if}} diff --git a/views/eventgroup.handlebars b/views/eventgroup.handlebars index 8fbedbc..9658b60 100755 --- a/views/eventgroup.handlebars +++ b/views/eventgroup.handlebars @@ -10,9 +10,7 @@
{{#if editingEnabled}} - - {{else}} - + {{/if}}
@@ -85,6 +83,10 @@ Export as ICS + + {{#unless editingEnabled}} + + {{/unless}} @@ -103,12 +105,12 @@ - + {{/if}}
-
About
+
About
{{{parsedDescription}}}
@@ -268,7 +270,7 @@ window.groupData = {{{ json jsonData }}}; if (urlParams.has('show_edit')) { $('#editModal').modal('show'); - url.searchParams.delete('show_edit'); + url.searchParams.delete('show_edit'); history.replaceState(history.state, '', url.href); } @@ -339,4 +341,4 @@ window.groupData = {{{ json jsonData }}}; }); - \ No newline at end of file + -- cgit v1.2.3 From 80aa81a22ef00331942fe6d066e1f9d5e58df33f Mon Sep 17 00:00:00 2001 From: Raphael Kabo Date: Sun, 26 May 2024 21:16:22 +0100 Subject: fix cypress tests --- cypress/e2e/event.cy.ts | 2 +- cypress/support/commands.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/event.cy.ts b/cypress/e2e/event.cy.ts index d5366e2..eeaa629 100644 --- a/cypress/e2e/event.cy.ts +++ b/cypress/e2e/event.cy.ts @@ -217,7 +217,7 @@ describe("Events", () => { cy.createGroup({ eventGroupName: "Test Group", eventGroupDescription: "Test Group Description", - eventGroupURL: "testgroup", + eventGroupURL: "https://example.com", hostName: "Test Host", creatorEmail: "test@example.com", }); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index eadcd20..6757255 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -46,7 +46,7 @@ declare namespace Cypress { hostName: string; creatorEmail: string; }, - isPublic: boolean, + isPublic?: boolean, ): Chainable; } } -- cgit v1.2.3