Skip to content
Snippets Groups Projects
Commit 92683e73 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

do not open iframe with invalid url and show hint in vue component, fixes #2169, fixes #2168

Closes #2169 and #2168

Merge request studip/studip!1640
parent 6721569c
No related branches found
No related tags found
No related merge requests found
<?php <?php
/** /**
* @var QuestionnaireQuestion $vote * @var QuestionnaireInfo $vote
*/ */
?> ?>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<?= Icon::create('info-circle', Icon::ROLE_INFO)->asImg(20) ?> <?= Icon::create('info-circle', Icon::ROLE_INFO)->asImg(20) ?>
</div> </div>
<div class="description"> <div class="description">
<? if (isset($vote->questiondata['url']) && trim($vote->questiondata['url'])) : ?> <? if ($vote->hasValidURL()) : ?>
<iframe <?= is_internal_url($vote->questiondata['url']) ? 'sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts"' : '' ?> <iframe <?= is_internal_url($vote->questiondata['url']) ? 'sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-scripts"' : '' ?>
src="<?= htmlReady($vote->questiondata['url']) ?>"></iframe> src="<?= htmlReady($vote->questiondata['url']) ?>"></iframe>
<? endif ?> <? endif ?>
......
...@@ -63,4 +63,15 @@ class QuestionnaireInfo extends QuestionnaireQuestion implements QuestionType ...@@ -63,4 +63,15 @@ class QuestionnaireInfo extends QuestionnaireQuestion implements QuestionType
{ {
return []; return [];
} }
/**
* Return whether a given url is valid.
* @return bool
*/
public function hasValidURL(): bool
{
return !empty($this->questiondata['url'])
&& trim($this->questiondata['url'])
&& filter_var($this->questiondata['url'], FILTER_VALIDATE_URL);
}
} }
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<div class="vote_edit"> <div class="vote_edit">
<label> <label>
{{ $gettext('Link eines Videos oder einer anderen Informationsseite (optional)') }} {{ $gettext('Link eines Videos oder einer anderen Informationsseite (optional)') }}
<input type="text" v-model="val_clone.url" ref="autofocus"> <input type="url" v-model="val_clone.url" ref="infoUrl"
@input="checkValidity()">
</label> </label>
<div class="formpart"> <div class="formpart">
...@@ -24,7 +25,7 @@ export default { ...@@ -24,7 +25,7 @@ export default {
value: { value: {
type: Object, type: Object,
required: false, required: false,
default: function () { default() {
return { return {
url: '', url: '',
description: '' description: ''
...@@ -36,14 +37,26 @@ export default { ...@@ -36,14 +37,26 @@ export default {
required: false required: false
} }
}, },
data: function () { data () {
return { return {
val_clone: '' val_clone: this.value,
}; };
}, },
mounted: function () { methods: {
this.val_clone = this.value; checkValidity() {
this.$refs.autofocus.focus(); this.$refs.infoUrl.setCustomValidity('');
if (!this.$refs.infoUrl.checkValidity()) {
this.$refs.infoUrl.setCustomValidity(
this.$gettext('Der eingegebene Link ist nicht korrekt und wird nicht angezeigt werden.')
);
this.$refs.infoUrl.reportValidity();
}
}
},
mounted() {
this.$refs.infoUrl.focus();
this.checkValidity();
}, },
watch: { watch: {
value (new_val) { value (new_val) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment