Skip to content

Commit 84b5866

Browse files
committed
Reduce duplication in the pickPlatformItem helper function
Also, tweak code/comment used when handling "GoToR" destinations.
1 parent 95f62f3 commit 84b5866

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

src/core/catalog.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,18 +1628,20 @@ class Catalog {
16281628
/* xref = */ null,
16291629
/* skipContent = */ true
16301630
);
1631-
const { rawFilename } = fs.serializable;
1632-
url = rawFilename;
1631+
({ rawFilename: url } = fs.serializable);
16331632
} else if (typeof urlDict === "string") {
16341633
url = urlDict;
1634+
} else {
1635+
break;
16351636
}
16361637

16371638
// NOTE: the destination is relative to the *remote* document.
16381639
const remoteDest = fetchRemoteDest(action);
1639-
if (remoteDest && typeof url === "string") {
1640+
if (remoteDest) {
16401641
// NOTE: We don't use the `updateUrlHash` function here, since
1641-
// the `createValidAbsoluteUrl` function (see below) already
1642-
// handles parsing and validation of the final URL.
1642+
// the `createValidAbsoluteUrl` function (see below) already handles
1643+
// parsing/validation of the final URL and manual splitting also
1644+
// ensures that the `unsafeUrl` property will be available/correct.
16431645
url = /* baseUrl = */ url.split("#", 1)[0] + "#" + remoteDest;
16441646
}
16451647
// The 'NewWindow' property, equal to `LinkTarget.BLANK`.

src/core/file_spec.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,13 @@ import { BaseStream } from "./base_stream.js";
1818
import { Dict } from "./primitives.js";
1919

2020
function pickPlatformItem(dict) {
21-
if (!(dict instanceof Dict)) {
22-
return null;
23-
}
24-
// Look for the filename in this order:
25-
// UF, F, Unix, Mac, DOS
26-
if (dict.has("UF")) {
27-
return dict.get("UF");
28-
} else if (dict.has("F")) {
29-
return dict.get("F");
30-
} else if (dict.has("Unix")) {
31-
return dict.get("Unix");
32-
} else if (dict.has("Mac")) {
33-
return dict.get("Mac");
34-
} else if (dict.has("DOS")) {
35-
return dict.get("DOS");
21+
if (dict instanceof Dict) {
22+
// Look for the filename in this order: UF, F, Unix, Mac, DOS
23+
for (const key of ["UF", "F", "Unix", "Mac", "DOS"]) {
24+
if (dict.has(key)) {
25+
return dict.get(key);
26+
}
27+
}
3628
}
3729
return null;
3830
}

0 commit comments

Comments
 (0)