1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Re-factor the parameter parsing/validation in getDocument

This is very old code, where we loop through the user-provided options and build an internal parameter object. To prevent errors we also need to ensure that the parameters are correct/valid, which is especially important for the ones that are sent to the worker-thread such that structured cloning won't fail.[1]

Over the years this has led to more and more code being added in `getDocument` to validate the user-provided options, and at this point *most* of them have at least basic validation. However the way that this is implemented feels slightly backwards, since we first build the internal parameter object and only *afterwards* validate those parameters.[2]

Hence this patch changes the `getDocument` function to instead check/validate the supported options upfront, and then *explicitly* build the internal parameter object with only the needed properties.

---
[1] Note the supported types at https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types

[2] The internal parameter object may also, because of the loop, end up with lots of unnecessary properties since anything that the user provides is being copied.
This commit is contained in:
Jonas Jenwald 2023-01-29 12:21:21 +01:00
parent e698664927
commit 512aa50fdd
2 changed files with 174 additions and 180 deletions

View file

@ -932,12 +932,10 @@ const PDFViewerApplication = {
) {
// The Firefox built-in viewer always calls `setTitleUsingUrl`, before
// `initPassiveLoading`, and it never provides an `originalUrl` here.
if (args.originalUrl) {
this.setTitleUsingUrl(args.originalUrl, /* downloadUrl = */ args.url);
delete args.originalUrl;
} else {
this.setTitleUsingUrl(args.url, /* downloadUrl = */ args.url);
}
this.setTitleUsingUrl(
args.originalUrl || args.url,
/* downloadUrl = */ args.url
);
}
// Set the necessary API parameters, using all the available options.
const apiParams = AppOptions.getAll(OptionKind.API);