Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix saving annotations in paths with special characters #1151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danxuliu
Copy link
Member

Fixes #1102

The filename may contain characters that are not compatible with a URL path, so it needs to be explicitly encoded. Otherwise the upload could fail (for example, if the filename contains % followed by a letter, which would cause the server to fail to decode the path and return a 400 Bad request error) or even overwrite a different file (for example, if the filename contains #, which would cause the rest of the path to be ignored).

How to test (scenario 1)

  • Open the Files app
  • Ensure that there is no folder or file named just test
  • Create a new folder named test#folder
  • Open the new folder
  • Upload a PDF file
  • Open the PDF file
  • Add an annotation
  • Save the PDF file
  • Close the PDF file
  • Open it again

Result with this pull request

The annotation is in the file

Result without this pull request

The annotation is not in the file. If the root folder is opened again there is now a file named test in it.

How to test (scenario 2)

  • Open the Files app
  • Create a new folder named #test
  • Open the new folder
  • Upload a PDF file
  • Open the PDF file
  • Add an annotation
  • Save the PDF file

Result with this pull request

The file is saved

Result without this pull request

An error is shown and the file is not saved. The "Network" tab of the browser development tools show that the request failed with "409 Conflict" (as it tried to overwrite the root folder).

How to test (scenario 3)

  • Open the Files app
  • Create a new folder named test%folder
  • Open the new folder
  • Upload a PDF file
  • Open the PDF file
  • Add an annotation
  • Save the PDF file

Result with this pull request

The file is saved

Result without this pull request

An error is shown and the file is not saved. The "Network" tab of the browser development tools show that the request failed with "400 Bad request" (as %f in the path could not be decoded).

@nextcloud/paths was already an implicit dependency, but now it is made
explicit to use the functions it provides in the PDF viewer code.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
The filename may contain characters that are not compatible with a URL
path, so it needs to be explicitly encoded. Otherwise the upload could
fail (for example, if the filename contains "%" followed by a letter,
which would cause the server to fail to decode the path and return a
"400 Bad request" error) or even overwrite a different file (for
example, if the filename contains "#", which would cause the rest of the
path to be ignored).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu
Copy link
Member Author

/compile /

@danxuliu
Copy link
Member Author

/backport to stable31

@danxuliu
Copy link
Member Author

/backport to stable30

@danxuliu
Copy link
Member Author

/backport to stable29

@danxuliu danxuliu requested a review from szaimen February 21, 2025 16:51
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDF Comments can not be saved if path containes a #
2 participants