fix: Render valid urls only in custom attributes (#3921)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
import { isValidURL } from '../helper/URLHelper';
|
||||
export default {
|
||||
computed: {
|
||||
...mapGetters({
|
||||
@@ -63,16 +63,11 @@ export default {
|
||||
Number.isInteger(Number(attributeValue)) && Number(attributeValue) > 0
|
||||
);
|
||||
},
|
||||
isAttributeLink(attributeValue) {
|
||||
/* eslint-disable no-useless-escape */
|
||||
const URL_REGEX = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/gm;
|
||||
return URL_REGEX.test(attributeValue);
|
||||
},
|
||||
attributeDisplayType(attributeValue) {
|
||||
if (this.isAttributeNumber(attributeValue)) {
|
||||
return 'number';
|
||||
}
|
||||
if (this.isAttributeLink(attributeValue)) {
|
||||
if (isValidURL(attributeValue)) {
|
||||
return 'link';
|
||||
}
|
||||
return 'text';
|
||||
|
||||
@@ -92,18 +92,6 @@ describe('attributeMixin', () => {
|
||||
expect(wrapper.vm.attributeDisplayType(9988)).toBe('number');
|
||||
});
|
||||
|
||||
it('return true if link is passed', () => {
|
||||
const Component = {
|
||||
render() {},
|
||||
title: 'TestComponent',
|
||||
mixins: [attributeMixin],
|
||||
};
|
||||
const wrapper = shallowMount(Component, { store, localVue });
|
||||
expect(wrapper.vm.isAttributeLink('https://www.chatwoot.com/pricing')).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it('return true if number is passed', () => {
|
||||
const Component = {
|
||||
render() {},
|
||||
|
||||
Reference in New Issue
Block a user