Skip to content
Snippets Groups Projects
Commit deccccd1 authored by Ron Lucke's avatar Ron Lucke Committed by Jan-Hendrik Willms
Browse files

fix #3823

Closes #3823

Merge request studip/studip!2702
parent 7657df71
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
"type": "object", "type": "object",
"properties": { "properties": {
"url": { "url": {
"type": "string" "type": "string",
"format": "uri"
}, },
"title": { "title": {
"type": "string" "type": "string"
...@@ -36,4 +37,4 @@ ...@@ -36,4 +37,4 @@
"required": [ "required": [
], ],
"additionalProperties": true "additionalProperties": true
} }
\ No newline at end of file
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</label> </label>
<label> <label>
{{ $gettext('URL') }} {{ $gettext('URL') }}
<input type="text" v-model="currentUrl" @change="setProtocol" /> <input type="text" v-model="currentUrl" @change="updateUrl" />
</label> </label>
<label> <label>
{{ $gettext('Höhe') }} {{ $gettext('Höhe') }}
...@@ -139,6 +139,7 @@ export default { ...@@ -139,6 +139,7 @@ export default {
return { return {
currentTitle: '', currentTitle: '',
currentUrl: '', currentUrl: '',
currentUrlIsValid: true,
currentHeight: '', currentHeight: '',
currentSubmitUserId: '', currentSubmitUserId: '',
currentSubmitParam: '', currentSubmitParam: '',
...@@ -198,6 +199,7 @@ export default { ...@@ -198,6 +199,7 @@ export default {
}, },
methods: { methods: {
...mapActions({ ...mapActions({
companionError: 'companionError',
updateBlock: 'updateBlockInContainer', updateBlock: 'updateBlockInContainer',
}), }),
initCurrentData() { initCurrentData() {
...@@ -228,8 +230,35 @@ export default { ...@@ -228,8 +230,35 @@ export default {
} }
} }
}, },
validateUrl() {
this.currentUrlIsValid = this.isValidUrl(this.currentUrl);
},
isValidUrl(urlString) {
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' + // validate protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
'(\\#[-a-z\\d_]*)?$',
'i'
); // validate fragment locator
return !!urlPattern.test(urlString);
},
updateUrl() {
this.setProtocol();
this.validateUrl();
},
storeBlock() { storeBlock() {
if (!this.currentUrlIsValid) {
this.companionError({
info: this.$gettext('Bitte geben Sie eine gültige URL ein.')
});
return false;
}
let attributes = {}; let attributes = {};
attributes.payload = {}; attributes.payload = {};
attributes.payload.title = this.currentTitle; attributes.payload.title = this.currentTitle;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment