fix: Invalid portal domain validation (#6166)

* fix: Invalid portal domain validation


Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Sivin Varghese
2023-01-09 13:42:19 +05:30
committed by GitHub
parent 4172cb4b23
commit 0a65a233d7
3 changed files with 23 additions and 2 deletions

View File

@@ -81,7 +81,8 @@
</template>
<script>
import { required, url, minLength } from 'vuelidate/lib/validators';
import { required, minLength } from 'vuelidate/lib/validators';
import { isDomain } from 'shared/helpers/Validators';
import thumbnail from 'dashboard/components/widgets/Thumbnail';
import { convertToCategorySlug } from 'dashboard/helper/commons.js';
import { buildPortalURL } from 'dashboard/helper/portalHelper';
@@ -121,7 +122,7 @@ export default {
required,
},
domain: {
url,
isDomain,
},
},
computed: {

View File

@@ -17,3 +17,7 @@ export const isValidPassword = value => {
);
};
export const isNumber = value => /^\d+$/.test(value);
export const isDomain = value => {
const domainRegex = /^([\p{L}0-9]+(-[\p{L}0-9]+)*\.)+[a-z]{2,}$/gmu;
return domainRegex.test(value);
};

View File

@@ -1,6 +1,7 @@
import { shouldBeUrl } from '../Validators';
import { isValidPassword } from '../Validators';
import { isNumber } from '../Validators';
import { isDomain } from '../Validators';
describe('#shouldBeUrl', () => {
it('should return correct url', () => {
@@ -35,3 +36,18 @@ describe('#isNumber', () => {
expect(isNumber('string')).toEqual(false);
});
});
describe('#isDomain', () => {
it('should return correct domain', () => {
expect(isDomain('test.com')).toEqual(true);
expect(isDomain('www.test.com')).toEqual(true);
});
it('should return wrong domain', () => {
expect(isDomain('test')).toEqual(false);
expect(isDomain('test.')).toEqual(false);
expect(isDomain('test.123')).toEqual(false);
expect(isDomain('http://www.test.com')).toEqual(false);
expect(isDomain('https://test.in')).toEqual(false);
});
});