@@ -56,6 +56,7 @@ export async function getMapResults({
56
56
allowExternalLinks,
57
57
abort = new AbortController ( ) . signal , // noop
58
58
mock,
59
+ filterByPath = true ,
59
60
} : {
60
61
url : string ;
61
62
search ?: string ;
@@ -70,6 +71,7 @@ export async function getMapResults({
70
71
allowExternalLinks ?: boolean ;
71
72
abort ?: AbortSignal ;
72
73
mock ?: string ;
74
+ filterByPath ?: boolean ;
73
75
} ) : Promise < MapResult > {
74
76
const id = uuidv4 ( ) ;
75
77
let links : string [ ] = [ url ] ;
@@ -247,6 +249,29 @@ export async function getMapResults({
247
249
links = links . filter ( ( x ) => isSameSubdomain ( x , url ) ) ;
248
250
}
249
251
252
+ // Filter by path if enabled
253
+ if ( filterByPath && ! allowExternalLinks ) {
254
+ try {
255
+ const urlObj = new URL ( url ) ;
256
+ const urlPath = urlObj . pathname ;
257
+ // Only apply path filtering if the URL has a significant path (not just '/' or empty)
258
+ // This means we only filter by path if the user has not selected a root domain
259
+ if ( urlPath && urlPath !== '/' && urlPath . length > 1 ) {
260
+ links = links . filter ( link => {
261
+ try {
262
+ const linkObj = new URL ( link ) ;
263
+ return linkObj . pathname . startsWith ( urlPath ) ;
264
+ } catch ( e ) {
265
+ return false ;
266
+ }
267
+ } ) ;
268
+ }
269
+ } catch ( e ) {
270
+ // If URL parsing fails, continue without path filtering
271
+ logger . warn ( `Failed to parse URL for path filtering: ${ url } ` , { error : e } ) ;
272
+ }
273
+ }
274
+
250
275
// remove duplicates that could be due to http/https or www
251
276
links = removeDuplicateUrls ( links ) ;
252
277
}
@@ -300,6 +325,7 @@ export async function mapController(
300
325
plan : req . auth . plan ,
301
326
abort : abort . signal ,
302
327
mock : req . body . useMock ,
328
+ filterByPath : req . body . filterByPath !== false ,
303
329
} ) ,
304
330
...( req . body . timeout !== undefined ? [
305
331
new Promise ( ( resolve , reject ) => setTimeout ( ( ) => {
0 commit comments