From fc7488e57289b0f7cde2f17531d43c491fb17217 Mon Sep 17 00:00:00 2001
From: Dmytro Bogatov <dmytro@dbogatov.org>
Date: Sat, 6 Feb 2021 22:36:27 -0500
Subject: [PATCH] Fix bug when one URL in a file.

---
 package.json        | 2 +-
 src/index.ts        | 4 ++--
 src/inspector.ts    | 4 ++--
 test/process-url.ts | 8 ++++----
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/package.json b/package.json
index 7d878c6..6fa7ef2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "broken-links-inspector",
-	"version": "1.3.3",
+	"version": "1.3.4",
 	"description": "Extract and recursively check all URLs reporting broken ones",
 	"main": "dist/inspector.js",
 	"types": "dist/inspector.d.ts",
diff --git a/src/index.ts b/src/index.ts
index dc0cef0..d7cf211 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,7 +7,7 @@ import { ConsoleReporter, JUnitReporter } from "./report"
 import fs from "fs/promises"
 
 commander
-	.version("1.3.3")
+	.version("1.3.4")
 	.description("Extract and recursively check all URLs reporting broken ones\n\nDedicated to Daria Bogatova \u2665")
 
 commander
@@ -70,7 +70,7 @@ commander
 			process.exit(0)
 		}
 
-		const result = await inspector.processURL(urls, urls.length == 1 ? inspectObj.recursive as boolean : false)
+		const result = await inspector.processURL(urls, inspectObj.recursive, url.startsWith("file://"))
 
 		for (const reporter of inspectObj.reporters as string[]) {
 			switch (reporter) {
diff --git a/src/inspector.ts b/src/inspector.ts
index 1ecbf35..ea51a7f 100644
--- a/src/inspector.ts
+++ b/src/inspector.ts
@@ -71,7 +71,7 @@ export class Inspector {
 		private readonly httpClient: IHttpClient = new AxiosHttpClient(config.timeout, config.acceptedCodes)
 	) { }
 
-	async processURL(originalUrls: URL[], recursive: boolean): Promise<Result> {
+	async processURL(originalUrls: URL[], recursive: boolean, fomFile: boolean): Promise<Result> {
 
 		const result = new Result(this.config.ignoreSkipped, this.config.disablePrint)
 		// [url, GET, attempts, parent?]
@@ -90,7 +90,7 @@ export class Inspector {
 				}
 				// Recursive is only done for one original URL : originalUrls[0]
 				const shouldParse =
-					(originalUrls.length == 1 && url == originalUrls[0].href)
+					(!fomFile && url == originalUrls[0].href)
 					|| (recursive && originalUrls[0].origin == new URL(url).origin)
 
 				if (
diff --git a/test/process-url.ts b/test/process-url.ts
index f4dc77a..519399d 100644
--- a/test/process-url.ts
+++ b/test/process-url.ts
@@ -171,7 +171,7 @@ describe("process mock URL", function () {
 			)
 			const unhook_intercept = intercept(_ => { return "" })
 
-			const result = await inspector.processURL([new URL("https://original.com")], recursive)
+			const result = await inspector.processURL([new URL("https://original.com")], recursive, false)
 
 			unhook_intercept()
 
@@ -270,7 +270,7 @@ describe("process real URL", async () => {
 		config,
 		new AxiosHttpClient(config.timeout, config.acceptedCodes)
 	)
-	await inspector.processURL([new URL("https://dbogatov.org")], false)
+	await inspector.processURL([new URL("https://dbogatov.org")], false, false)
 })
 
 describe("process URL single-threaded", async () => {
@@ -282,7 +282,7 @@ describe("process URL single-threaded", async () => {
 		config,
 		new AxiosHttpClient(config.timeout, config.acceptedCodes)
 	)
-	await inspector.processURL([new URL("https://dbogatov.org")], false)
+	await inspector.processURL([new URL("https://dbogatov.org")], false, false)
 })
 
 describe("process multiple URLs", async () => {
@@ -293,7 +293,7 @@ describe("process multiple URLs", async () => {
 		config,
 		new AxiosHttpClient(config.timeout, config.acceptedCodes)
 	)
-	await inspector.processURL([new URL("https://dbogatov.org"), new URL("https://bogatova.org")], false)
+	await inspector.processURL([new URL("https://dbogatov.org"), new URL("https://bogatova.org")], false, false)
 })
 
 describe("result", () => {
-- 
GitLab