Skip to content

Commit

Permalink
fix: Return a deep copy to prevent external mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent-Bouisset authored and peaBerberian committed Jun 24, 2024
1 parent 7b12386 commit 77cc51f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/resolve_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ const MAX_URL_CACHE_ENTRIES = 200;
*/
function parseURL(url: string): IParsedURL {
if (parsedUrlCache.has(url)) {
return parsedUrlCache.get(url) as IParsedURL;
// Return a deep copy to prevent external mutation
return { ...(parsedUrlCache.get(url) as IParsedURL) };
}
const matches = url.match(urlComponentRegex);
let parsed: IParsedURL;
Expand All @@ -210,7 +211,8 @@ function parseURL(url: string): IParsedURL {
parsedUrlCache.clear();
}
parsedUrlCache.set(url, parsed);
return parsed;
// Return a deep copy to prevent external mutation
return { ...parsed };
}
/**
* Formats a parsed URL into a string.
Expand Down

0 comments on commit 77cc51f

Please sign in to comment.