1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00
Commit graph

1286 commits

Author SHA1 Message Date
Calixte Denizet
d1db8d6294 Avoid to display an alert or a confirm dialog if the message is empty
It fixes #19171.
2024-12-05 21:04:07 +01:00
Jonas Jenwald
f8d11a3a3a
Merge pull request #19074 from Rob--W/issue-12744-test
Add test cases for redirected responses
2024-12-02 19:06:55 +01:00
Rob Wu
f97b4b9a66 Add test cases for redirected responses
Regression tests for issue #12744 and PR #19028
2024-12-02 17:57:49 +01:00
Rob Wu
28b0220bc2 Replace createTemporaryNodeServer with TestPdfsServer
Some tests rely on the presence of a server that serves PDF files.
When tests are run from a web browser, the test files and PDF files are
served by the same server (WebServer), but in Node.js that server is not
around.

Currently, the tests that depend on it start a minimal Node.js server
that re-implements part of the functionality from WebServer.

To avoid code duplication when tests depend on more complex behaviors,
this patch replaces createTemporaryNodeServer with the existing
WebServer, wrapped in a new test utility that has the same interface in
Node.js and non-Node.js environments (=TestPdfsServer).

This patch has been tested by running the refactored tests in the
following three configurations:

1. From the browser:
   - http://localhost:8888/test/unit/unit_test.html?spec=api
   - http://localhost:8888/test/unit/unit_test.html?spec=fetch_stream

2. Run specific tests directly with jasmine without legacy bundling:
   `JASMINE_CONFIG_PATH=test/unit/clitests.json ./node_modules/.bin/jasmine --filter='^api|^fetch_stream'`

3. `gulp unittestcli`
2024-12-02 17:57:49 +01:00
Calixte Denizet
2a337082c0 Build date consistently (in term of tz) when executing some embedded JS (bug 1934157)
The date was create in UTC+0 and then amended in using set-Month/Date which take into account
the user timezone.
With this patch we build all the date in the user timezone.
2024-11-29 19:50:21 +01:00
Jonas Jenwald
65f20b0392
Merge pull request #19121 from Snuffleupagus/more-stopEvent
Use the `stopEvent` helper function everywhere possible
2024-11-28 17:21:34 +01:00
calixteman
c784a24d45
Merge pull request #19122 from calixteman/issue19120
Correctly compute the mapping between text and normalized text when it contains a compound word on two lines
2024-11-28 17:13:09 +01:00
Calixte Denizet
aa9503e51f Correctly compute the mapping between text and normalized text when it contains a compound word on two lines
It fixes #19120.

The original text doesn't contain the cr so we must take that into account.
2024-11-28 15:56:04 +01:00
Calixte Denizet
cee65fcd4e [Editor] Add a new base class to allow to add a drawing in the SVG layer.
This patch makes a clear separation between the way to draw and the editing stuff.
It adds a class DrawEditor which should be extended in order to create new drawing tools.
As an example, the ink tool has been rewritten in order to use it.
2024-11-28 15:23:03 +01:00
Jonas Jenwald
e1760aab8d Use the stopEvent helper function everywhere possible 2024-11-28 13:25:56 +01:00
Rob Wu
131d4650a5 Drop trailing whitespace from test/unit/api_spec.js
test/unit/api_spec.js is the only JS file in the tree with trailing
whitespace. Because `trim_trailing_whitespace = true` in .editorconfig,
any editor supporting EditorConfig would trim whitespace when the file
is changed, which results in test failures.

This commit fixes the issue by trimming the trailing whitespace and
adjusting the test expectations.
2024-11-24 23:37:16 +01:00
Tim van der Meij
8ae5b4e442
Merge pull request #19096 from Rob--W/test-server-hardening
Fix path traversal issue in createTemporaryNodeServer
2024-11-24 15:30:22 +01:00
Jonas Jenwald
6a015588b9 Ensure that the response-origin of range requests match the full request (issue 12744)
The following cases are excluded in the patch:
 - The Firefox PDF Viewer, since it has been fixed on the platform side already; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1683940

 - The `PDFNodeStream`-implementation, used in Node.js environments, since after recent changes that code only supports `file://`-URLs.

Also updates the `PDFNetworkStreamFullRequestReader.read`-method to await the headers before returning any data, similar to the implementation in `src/display/fetch_stream.js`.

*Note:* The relevant unit-tests are updated to await the `headersReady` Promise before dispatching range requests, since that's consistent with the actual usage in the `src/`-folder.
2024-11-24 10:08:29 +01:00
Rob Wu
17da8ee8fa Fix path traversal issue in createTemporaryNodeServer
The test-only createTemporaryNodeServer helper featured a path traversal
vulnerability. This enables attackers with network access to the device
to read arbitrary files while unit tests are running that activate this
test server.

This patch fixes the issue by validation of paths.

To test this vulnerability before the patch:

1. Run the test-only server:

```
node -e 'console.log(require("./test/unit/test_utils.js").createTemporaryNodeServer().port)
```

2. From another terminal, send the following request (modify the port to
   the port reported in the previous step):

```
curl --path-as-is http://localhost:45755/../../package.json
```

Before the patch, the second step would traverse the directory, and
return results from the root of the PDF.js repository, instead of files
within test/pdfs/.

With the patch, the server refuses the request with HTTP status 400.
2024-11-23 21:32:24 +01:00
Jonas Jenwald
c290a12ce1 Simplify the getUuid helper function
We can remove most feature testing from this helper function, with the exception of `randomUUID` since that's only available in "secure contexts", and also remove the fallback code-path.
Note that this code was only added for Node.js compatibility, and it's no longer necessary now that the minimum support version is `20`; see also https://developer.mozilla.org/en-US/docs/Web/API/Crypto#browser_compatibility

Finally, this patch also adds a basic unit-test for the helper function.
2024-11-21 13:11:10 +01:00
calixteman
8a8b69f456
Merge pull request #19054 from calixteman/issue18630
When saving some annotations with the same name, set the value in the parent
2024-11-17 18:00:48 +01:00
Calixte Denizet
2da586527f When saving some annotations with the same name, set the value in the parent
It fixes #18630.
2024-11-17 15:55:20 +01:00
Jonas Jenwald
2c0cc48d1b Replace the forEach method in Dict with "proper" iteration support 2024-11-17 12:45:32 +01:00
Jonas Jenwald
fe5967c84e
Merge pull request #19029 from nicolo-ribaudo/eslint-flat-config
Migrate to ESLint flat config
2024-11-12 16:22:54 +01:00
Nicolò Ribaudo
9e6ff979db
Migrate to ESLint flat config
Flat config is the new config system used by ESLint 9.
To make the migration easier, they also added
flat config support to ESLint 8.

This commit migrates the various ESLint configs in the repository to use
the new system, **without** upgrading to ESLint 9 yet.
2024-11-12 16:15:17 +01:00
Calixte Denizet
4bf7787084 Simplify saving added/modified annotations.
Having this map to collect the different changes will allow to know if some objects have already been modified.
2024-11-12 10:59:38 +01:00
Jonas Jenwald
1a56b35af7
Merge pull request #19003 from Snuffleupagus/api-unittest-image-helpers
Add helper functions to load image blob/bitmap data in `test/unit/api_spec.js`
2024-11-06 09:11:28 +01:00
Jonas Jenwald
e92a929a58 Try to improve handling of missing trailer dictionaries in XRef.indexObjects (issue 18986)
The problem with the referenced PDF document has nothing to do with invalid dates, as the issue seems to suggest, but rather with the fact that it has neither an XRef table nor a trailer dictionary.
Given that crucial parts of the internal document structure is missing, you might argue that it's not really a PDF document.

In an attempt to support this kind of corruption, we'll simply iterate through all (previously found) XRef entries and pick one that *might* be a valid /Root dictionary.
There's obviously no guarantee that this works, and it might not be fast in larger PDF documents, but at least it cannot be any worse than *immediately* throwing `InvalidPDFException` as we previously did here.

*Please note:* I'm totally fine with this patch being rejected, since it's somewhat questionable if we should actually attempt to support "PDF documents" with this level of corruption.
2024-11-05 18:19:26 +01:00
Jonas Jenwald
f2fb3b95ce Add helper functions to load image blob/bitmap data in test/unit/api_spec.js
This avoids repeating the same code multiple times, and as part of the changes we'll also utilize existing PDF.js helpers more.
2024-11-04 14:09:34 +01:00
Jonas Jenwald
cbf0ca71bf [api-minor] Only support the Fetch API for "remote" PDF documents in Node.js environments
The Fetch API has been supported since Node.js version 18, see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility
2024-11-03 16:18:10 +01:00
Jonas Jenwald
c7407230c1 [api-minor] Load Node.js packages/polyfills with process.getBuiltinModule
This allows *synchronous* loading of Node.js modules and (indirectly) packages, thus simplifying the code a fair bit.
2024-11-03 16:13:58 +01:00
Jonas Jenwald
f78a8f3c54 Use the toBase64Util helper function in the unit-tests 2024-11-03 11:25:19 +01:00
Tim van der Meij
5f77b907eb
Merge pull request #18997 from Snuffleupagus/Node-enable-Blob-unittest
Enable the 'gets PDF filename from query string appended to "blob:" URL' unit-test in Node.js
2024-11-03 11:11:36 +01:00
Jonas Jenwald
faf9e32ecb Enable the "should have an alt attribute from toolTip" unit-test in Node.js
Despite the pending-message mentioning "Image", this appears to be another case where the code actually depends on [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#browser_compatibility); note cf3ca8b5bc/src/core/xfa/template.js (L3453)
2024-11-03 00:15:44 +01:00
Jonas Jenwald
15fbee158c Enable the 'gets PDF filename from query string appended to "blob:" URL' unit-test in Node.js
The necessary functionality has been supported in Node.js for quite some time now, please see:
 - https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static#browser_compatibility
2024-11-02 23:53:03 +01:00
Jonas Jenwald
4e12906061 Move the various DOM-factories into their own files
- Over time the number and size of these factories have increased, especially the `DOMFilterFactory` class, and this split should thus aid readability/maintainability of the code.

 - By introducing a couple of new import maps we can avoid bundling the `DOMCMapReaderFactory`/`DOMStandardFontDataFactory` classes in the Firefox PDF Viewer, since they are dead code there given that worker-thread fetching is always being used.

 - This patch has been successfully tested, by running `$ ./mach test toolkit/components/pdfjs/`, in a local Firefox artifact-build.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `1.3` kilo-bytes, which isn't a lot but still cannot hurt.
2024-11-01 13:31:28 +01:00
calixteman
2bee3af0ee
Merge pull request #18967 from calixteman/bug1910431
Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431)
2024-10-28 09:36:34 +01:00
Calixte Denizet
230d7f9229 Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431) 2024-10-27 19:19:06 +01:00
Jonas Jenwald
b048420d21 [api-minor] Remove the CMapCompressionType enumeration
After the binary CMap format had been added there were also some ideas about *maybe* providing other formats, see [here](https://github.com/mozilla/pdf.js/pull/8064#issuecomment-279730182), however that was over seven years ago and we still only use binary CMaps.
Hence it now seems reasonable to simplify the relevant code by removing `CMapCompressionType` and instead just use a boolean to indicate the type of the built-in CMaps.
2024-10-24 11:08:16 +02:00
Jonas Jenwald
6c3336f04f Re-factor the DefaultFileReaderFactory unit-test helper
We can re-use the existing helpers from `src/display/` rather than re-implementing the functionality here.
2024-10-21 13:20:31 +02:00
Calixte Denizet
3103deaa44 Fix missing annotation parent in using the one from the Fields entry
Fixes #15096.
2024-10-04 20:00:19 +02:00
Calixte Denizet
c9050be863 [Editor] Add the possibility to save an updated stamp annotation (bug 1921291) 2024-10-02 11:45:16 +02:00
Calixte Denizet
0382dd0e25 [Editor] When deleting an annotation with popup, then delete the popup too 2024-09-26 17:52:25 +02:00
Calixte Denizet
fc1564f476 Correctly compute the font size when printing a text field with an auto font size (bug 1917734) 2024-09-25 14:05:54 +02:00
Jonas Jenwald
bb302dd993 [api-minor] Pass CanvasFactory/FilterFactory, rather than instances, to getDocument
This unifies the various factory-options, since it's consistent with `CMapReaderFactory`/`StandardFontDataFactory`, and ensures that any needed parameters will always be consistently provided when creating `CanvasFactory`/`FilterFactory`-instances.

As shown in the modified example this may simplify some custom implementations, since we now provide the ability to access the `CanvasFactory`-instance used with a particular `getDocument`-invocation.
2024-09-23 11:26:30 +02:00
Jonas Jenwald
0a621ba73a Use fs/promises in the Node.js unit-tests (PR 17714 follow-up)
This is available in all Node.js versions that we currently support, and using it allows us to remove callback-functions; please see https://nodejs.org/docs/latest-v18.x/api/fs.html#promises-api
2024-09-22 12:57:23 +02:00
Calixte Denizet
46fac8b2c1 [Editor] Take into account the device pixel ratio when drawing an added image
Fixes #18626.
2024-09-16 14:48:26 +02:00
Jonas Jenwald
c52e8485a7
Merge pull request #18731 from Snuffleupagus/TextLayer-ensureCtxFont
Ensure that textLayers can be rendered in parallel, without interfering with each other
2024-09-11 16:29:53 +02:00
Jonas Jenwald
5b3d3c7dd9 Ensure that textLayers can be rendered in parallel, without interfering with each other
Note that the textContent is returned in "chunks" from the API, through the use of `ReadableStream`s, and on the main-thread we're (normally) using just one temporary canvas in order to measure the size of the textLayer `span`s; see the [`#layout`](5b4c2fe1a8/src/display/text_layer.js (L396-L428)) method.

*Order of events, for parallel textLayer rendering:*
 1. Call [`render`](5b4c2fe1a8/src/display/text_layer.js (L155-L177)) of the textLayer for page A.
 2. Immediately call `render` of the textLayer for page B.
 3. The first text-chunk for pageA arrives, and it's parsed/layout which means updating the cached [fontSize/fontFamily](5b4c2fe1a8/src/display/text_layer.js (L409-L413)) for the textLayer of page A.
 4. The first text-chunk for pageB arrives, which means updating the cached fontSize/fontFamily *for the textLayer of page B* since this data is unique to each `TextLayer`-instance.
 5. The second text-chunk for pageA arrives, and we don't update the canvas-font since the cached fontSize/fontFamily still apply from step 3 above.

Where this potentially breaks down is between the last steps, since we're using just one temporary canvas for all measurements but have *individual* fontSize/fontFamily caches for each textLayer.
Hence it's possible that the canvas-font has actually changed, despite the cached values suggesting otherwise, and to address this we instead cache the fontSize/fontFamily globally through a new (static) helper method.

*Note:* Includes a basic unit-test, using dummy text-content, which fails on `master` and passes with this patch.

Finally, pun intended, ensure that temporary textLayer-data is cleared *before* the `render`-promise resolves to avoid any intermittent problems in the unit-tests.
2024-09-11 15:28:51 +02:00
Calixte Denizet
06f9d8002d Consider foo-\nBar as a compound word
Fixes #18693.
2024-09-11 15:01:54 +02:00
Calixte Denizet
bae32b4fd2 [JS] Let AFSpecial_KeystrokeEx match a format without 'decoration' (bug 1916714)
It'll let the user enter 1234567 instead of 123-4567 for example.
It works like this in other pdf viewers.
2024-09-09 20:29:14 +02:00
Tim van der Meij
c159cb1335
Merge pull request #18682 from Snuffleupagus/responseHeaders
Use response-`Headers` in the different `IPDFStream` implementations
2024-09-08 11:49:50 +02:00
Calixte Denizet
68332ec236 Avoid to have a white line around the canvas
The canvas must have the same dims as the page in order to avoid to see the page
background.
2024-09-07 20:12:29 +02:00
Jonas Jenwald
840cc5e0d4 Use response-Headers in the different IPDFStream implementations
Given that the `Headers` functionality is now available in all browsers/environments that we support, [see MDN](https://developer.mozilla.org/en-US/docs/Web/API/Headers#browser_compatibility), we can utilize "proper" `Headers` in the helper functions that are used to parse the response.
2024-09-07 12:34:53 +02:00
Calixte Denizet
ddba096191 Make tagged images visible for screen readers (bug 1708040)
The idea is to insert a span in the text layer with an aria-role set to img
and use the bounding box provided by the attribute field in the tag dict in
order to have non-null dimensions for the image to make it "visible".
2024-09-05 17:59:42 +02:00