Skip to content

Commit

Permalink
Update background.js
Browse files Browse the repository at this point in the history
Fixed recognizing unsafe and potentially unsafe links
  • Loading branch information
kenhendricks00 authored Nov 2, 2024
1 parent c017b02 commit 58d3520
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions platform/chromium/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ function extractUrlsFromBookmarks(html) {
return urls;
}

// Helper function to normalize URLs (removes trailing slashes, query parameters, and fragments)
// Helper function to normalize URLs (adds protocol if missing, removes trailing slashes, query parameters, and fragments)
function normalizeUrl(url) {
try {
// Check if the URL starts with "http" or "https", if not, prepend "https://"
if (!/^https?:\/\//i.test(url)) {
url = `https://${url}`;
}
const urlObj = new URL(url);
urlObj.search = ""; // Remove query parameters
urlObj.hash = ""; // Remove fragments
Expand Down Expand Up @@ -61,7 +65,7 @@ function extractUrlsFromFilterList(text) {
return text
.split("\n")
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("!")) // Ignore comments and empty lines
.filter((line) => line && !line.startsWith("!")) // Ignore comments
.map((line) => normalizeUrl(line))
.filter((url) => url !== null); // Filter out null values from invalid URLs
}
Expand Down

0 comments on commit 58d3520

Please sign in to comment.