Skip to content

Commit

Permalink
Better testing for invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
fallax committed Jan 4, 2025
1 parent 46be3de commit 025fd78
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,33 @@ function searchHtml(html, searchStrings)

// Our list of tests to be run on URLS
export const tests = [
{
phase: 'pre',
name: "invalidURL", // Skip checking this item if no consistent URL listed (this means we couldn't parse the URL)
test: (input, options, response) => !input.consistentURL,
reason: (input, options, response) => "Invalid URL"
},
{
phase: 'pre',
skipUrl: true,
name: "zeroLengthURL", // Skip checking this item if URL is zero length or null
test: (input, options, response) => input.currentURL.length == 0,
reason: (input, options, response) => "Empty URL"
},
{
phase: 'pre',
skipUrl: true,
name: "anchorURL", // Skip checking this item if URL starts with hash/pound symbol (is an anchor within the page)
test: (input, options, response) => input.currentURL[0] == "#",
reason: (input, options, response) => "Anchor URL - skipped"
},
{
phase: 'pre',
skipUrl: true,
name: "mailtoURL", // Skip checking this item if URL starts with hash/pound symbol (is an anchor within the page)
test: (input, options, response) => input.currentURL.startsWith("mailto"),
reason: (input, options, response) => "mailto URL - skipped"
},
{
phase: 'pre',
name: "invalidURL", // Skip checking this item if no consistent URL listed (this means we couldn't parse the URL)
test: (input, options, response) => !input.consistentURL,
reason: (input, options, response) => "Invalid URL"
},
{
phase: 'pre',
name: "tooManyRedirects", // Fail if too many redirects have been made
Expand All @@ -91,8 +105,7 @@ export const tests = [
},
{
phase: 'pre',
skipUrl: true,
name: "invalidURL", // Skip checking this item if the URL cannot be parsed
name: "invalidURL", // Fail this URL if the URL cannot be parsed
test: (input, options, response) =>
{
try {
Expand Down

0 comments on commit 025fd78

Please sign in to comment.