🐞 fix: change url validation to require scheme and allow path
This commit is contained in:
@@ -4,7 +4,11 @@
|
||||
|
||||
const isValidDomain = (domain) => {
|
||||
// Regular expression to validate a domain name
|
||||
const domainRegex = /^(?!:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
|
||||
// const domainRegex = /^(?!:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
|
||||
|
||||
// Regular expression to validate a domain name. Requires http or https prefix.
|
||||
// Allows for optional path after the domain.
|
||||
const domainRegex = /^https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/[^\s]*)?\/?$/;
|
||||
return domainRegex.test(domain);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ class SiteModel {
|
||||
/**
|
||||
* Inserts a new site into the database.
|
||||
*
|
||||
* @param {string} name - The name of the site.
|
||||
* @param {string} domainName - The domain name of the site.
|
||||
*
|
||||
* @returns {Promise<Object>} - The result of the insert operation.
|
||||
@@ -20,7 +19,7 @@ class SiteModel {
|
||||
async insert(domainName) {
|
||||
// validate inputs
|
||||
if (!domainName) {
|
||||
throw new Error('Name and domain name are required to insert a site.');
|
||||
throw new Error('Domain name is required to insert a site.');
|
||||
}
|
||||
|
||||
// validate domain name format
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,8 @@
|
||||
<legend class="fieldset-legend h3">Start a new test</legend>
|
||||
<div class="flex gap-0">
|
||||
<div class="w-fit m-0 p-0">
|
||||
<input type="text" class="input w-full border-r-0 rounded-r-none" name="domain" id="domain" placeholder="Site/URL to test" />
|
||||
<p class="label pt-2">Add either single URL or link to sitemap</p>
|
||||
<input type="text" class="input w-full border-r-0 rounded-r-none" name="domain" id="domain" placeholder="https://example.com/" />
|
||||
<p class="label pt-2">Single URL or link to sitemap, including "http" or "https"</p>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-info">Test</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user