Fix event URL validation and check if hostname is correct before showing

it

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-10-15 09:57:08 +02:00
parent 4727c8861e
commit f82c3b7492
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 8 additions and 4 deletions

View File

@ -38,7 +38,7 @@
</div> </div>
<b-field :label="$t('Website / URL')"> <b-field :label="$t('Website / URL')">
<b-input icon="link" v-model="event.onlineAddress" placeholder="URL" /> <b-input icon="link" type="url" v-model="event.onlineAddress" placeholder="URL" />
</b-field> </b-field>
<!--<b-field :label="$t('Category')"> <!--<b-field :label="$t('Category')">

View File

@ -118,7 +118,7 @@ import {ParticipantRole} from "@/types/event.model";
</div> </div>
</b-modal> </b-modal>
</div> </div>
<span class="online-address" v-if="event.onlineAddress"> <span class="online-address" v-if="event.onlineAddress && urlToHostname(event.onlineAddress)">
<b-icon icon="link"></b-icon> <b-icon icon="link"></b-icon>
<a :href="event.onlineAddress">{{ urlToHostname(event.onlineAddress) }}</a> <a :href="event.onlineAddress">{{ urlToHostname(event.onlineAddress) }}</a>
</span> </span>
@ -548,8 +548,12 @@ export default class Event extends EventMixin {
return this.event.options.maximumAttendeeCapacity - this.event.participantStats.participants; return this.event.options.maximumAttendeeCapacity - this.event.participantStats.participants;
} }
urlToHostname(url: string): string { urlToHostname(url: string): string|null {
try {
return (new URL(url)).hostname; return (new URL(url)).hostname;
} catch (e) {
return null;
}
} }
} }
</script> </script>