Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added regex checks for 'Link to Work' and 'Link to Creator Profile' #456

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
52 changes: 51 additions & 1 deletion src/components/AttributionDetailsStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
</v-input>
<v-input
v-model="workUrl"
v-validate="{ url: { require_protocol: true } }"
:label="$t('stepper.AD.form.work-url.label')"
:placeholder="$t('stepper.AD.form.work-url.placeholder')"
/>
<span v-if="attributionErrorMsg.workUrlError">{{ attributionErrorMsg.workUrlError }}</span>
<v-input
v-model="creatorProfileUrl"
:label="$t('stepper.AD.form.creator-profile.label')"
:placeholder="$t('stepper.AD.form.creator-profile.placeholder')"
/>
<span v-if="attributionErrorMsg.creatorProfileUrlError">{{ attributionErrorMsg.creatorProfileUrlError }}</span>
<v-input
v-if="currentLicenseAttributes.BY"
v-model="yearOfCreation"
:label="$t('stepper.AD.form.year-of-creation.label')"
:placeholder="$t('stepper.AD.form.year-of-creation.placeholder')"
/>
<span v-if="attributionErrorMsg.yearOfCreationError">{{ attributionErrorMsg.yearOfCreationError }}</span>
</form>

<app-modal
Expand All @@ -58,7 +62,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import { library } from '@fortawesome/fontawesome-svg-core';
library.add(faInfoCircle);

const regexTestString= /[(http(s)?):(www)?a-zA-Z0-9@:%._~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex has a number of problems (including #456 (comment)).

Maybe use The Perfect URL Regular Expression - Perfect URL Regex:

const regexTestString= /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/;

export default {
name: 'AttributionDetails',
components: { VInput, FontAwesomeIcon },
Expand All @@ -74,6 +78,7 @@ export default {
data() {
return {
showInfoModal: false,
attributionErrorMsg: [],
};
},
computed: {
Expand Down Expand Up @@ -119,10 +124,55 @@ export default {
},
},
},
watch: {
creatorProfileUrl(value){
this.attributionDetails.creatorProfileUrl = value;
this.validateCreatorProfileUrl(value);
},
workUrl(value){
this.attributionDetails.workUrl = value;
this.validateWorkUrl(value);
},
yearOfCreation(value){
this.attributionDetails.yearOfCreation = value;
this.validateYearOfCreation(value);
},
},
methods: {
toggleInfoModal() {
this.showInfoModal = !this.showInfoModal;
},
validateCreatorProfileUrl(value) {
if(value.length === 0){
this.attributionErrorMsg.creatorProfileUrlError = '';
}
else if (regexTestString.test(value)) {
this.attributionErrorMsg.creatorProfileUrlError = '';
} else {
this.attributionErrorMsg.creatorProfileUrlError = 'Please enter a valid URL.';
}
},
validateWorkUrl(value) {
if(value.length === 0){
this.attributionErrorMsg.workUrlError = '';
}
else if (regexTestString.test(value)) {
this.attributionErrorMsg.workUrlError = '';
} else {
this.attributionErrorMsg.workUrlError = 'Please enter a valid URL.';
}
},
validateYearOfCreation(value){
if(value.length === 0){
this.attributionErrorMsg.yearOfCreationError = '';
}
else if(Number(value)>= 1000 && Number(value)<=9999 && !value.includes('.')){
this.attributionErrorMsg.yearOfCreationError = '';
}
else {
this.attributionErrorMsg.yearOfCreationError = 'Please enter a valid year';
Copy link
Member

@TimidRobot TimidRobot Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two digit years are valid, even if imprecise. Also the text is nonblocking.

Please update text to something like: For clarity, please consider a four digit year

}
},
...mapMutations([
'setCreatorName',
'setCreatorProfileUrl',
Expand Down