mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-06 23:25:48 +02:00
Merge pull request #20690 from Snuffleupagus/getPdfFilenameFromUrl-searchParams-findLast
Reduce duplication when parsing `searchParams` in the `getPdfFilenameFromUrl` function
This commit is contained in:
commit
e07e8ed172
@ -395,19 +395,14 @@ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newURL.searchParams.size > 0) {
|
if (newURL.searchParams.size > 0) {
|
||||||
const values = Array.from(newURL.searchParams.values()).reverse();
|
const getLast = iterator => [...iterator].findLast(v => pdfRegex.test(v));
|
||||||
for (const value of values) {
|
|
||||||
if (pdfRegex.test(value)) {
|
// If any of the search parameters ends with ".pdf", return it.
|
||||||
// If any of the search parameters ends with ".pdf", return it.
|
const name =
|
||||||
return decode(value);
|
getLast(newURL.searchParams.values()) ??
|
||||||
}
|
getLast(newURL.searchParams.keys());
|
||||||
}
|
if (name) {
|
||||||
const keys = Array.from(newURL.searchParams.keys()).reverse();
|
return decode(name);
|
||||||
for (const key of keys) {
|
|
||||||
if (pdfRegex.test(key)) {
|
|
||||||
// If any of the search parameter keys ends with ".pdf", return it.
|
|
||||||
return decode(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user