Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Can't open PDF when filename or folder name contains a space or special character (' ', é, ...) #381

Closed
maxrekorder opened this issue May 15, 2021 · 104 comments · Fixed by #384
Labels

Comments

@maxrekorder
Copy link

maxrekorder commented May 15, 2021

🩹 Temporary fix (will be shipped in the next Nextcloud minor release only)

ℹ️ This is a temporary fix you can apply manually, from PR #384. To do this:

1) Replace the file at apps/files_pdfviewer/js/files_pdfviewer-main.js on your instance with this file from that PR

2) Clear your (each user must do it) browser's cache and try to open pdfs. This is a must-do, otherwise, the old file will be loaded from browser's cache !!


Steps to reproduce

  1. Create a New Folder
  2. Add a PDF file to to the folder. PDF filename containing a space (e.g. name it "Juergen Klopp.pdf").
  3. Open PDF file "Juergen Klopp.pdf"
  4. It also won't work if the folder contains a space

Expected behaviour

Open the PDF with PDF viewer

Actual behaviour

PDF.js Version 2.5.207 (build: 0974d6052)
Nachricht: Missing PDF "https://domain.org/remote.php/dav/files/user/New/Juergen%2520Klopp.pdf".

Server configuration detail

Operating system: Linux 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64

Webserver: Apache/2.4.41 (Ubuntu) (apache2handler)

Database: mysql 8.0.25

PHP version:

8.0.5
Modules loaded: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, Reflection, SPL, session, standard, sodium, apache2handler, mysqlnd, PDO, xml, apcu, bcmath, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, gmp, iconv, igbinary, imagick, intl, ldap, exif, mysqli, pdo_mysql, Phar, posix, readline, redis, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, Zend OPcache

Nextcloud version: 21.0.2 RC1 - 21.0.2.0

Updated from an older Nextcloud/ownCloud or fresh install:

Where did you install Nextcloud from: unknown

Signing status

Array
(
)

List of activated apps
Enabled:
 - accessibility: 1.7.0
 - apporder: 0.12.0
 - calendar: 2.2.1
 - circles: 0.21.2
 - cloud_federation_api: 1.4.0
 - comments: 1.11.0
 - contacts: 3.5.1
 - contactsinteraction: 1.2.0
 - dav: 1.17.1
 - documentserver_community: 0.1.9
 - federatedfilesharing: 1.11.0
 - federation: 1.11.0
 - files: 1.16.0
 - files_external: 1.12.0
 - files_pdfviewer: 2.1.0
 - files_rightclick: 1.0.0
 - files_sharing: 1.13.1
 - files_trashbin: 1.11.0
 - files_versions: 1.14.0
 - files_videoplayer: 1.10.0
 - firstrunwizard: 2.10.0
 - forms: 2.2.4
 - issuetemplate: 0.7.0
 - logreader: 2.6.0
 - lookup_server_connector: 1.9.0
 - notes: 4.0.4
 - notifications: 2.9.0
 - oauth2: 1.9.0
 - onlyoffice: 7.0.2
 - passman: 2.3.7
 - password_policy: 1.11.0
 - photos: 1.3.0
 - privacy: 1.5.0
 - provisioning_api: 1.11.0
 - recommendations: 1.0.0
 - serverinfo: 1.11.0
 - settings: 1.3.0
 - sharebymail: 1.11.0
 - support: 1.4.0
 - survey_client: 1.9.0
 - systemtags: 1.11.0
 - tasks: 0.13.6
 - text: 3.2.0
 - theming: 1.12.0
 - theming_customcss: 1.8.0
 - twofactor_backupcodes: 1.10.0
 - updatenotification: 1.11.0
 - user_status: 1.1.1
 - viewer: 1.5.0
 - weather_status: 1.1.0
 - workflowengine: 2.3.0
Disabled:
 - activity
 - admin_audit
 - bruteforcesettings
 - dashboard
 - encryption
 - mail
 - nextcloud_announcements
 - user_ldap
 - workflow_pdf_converter

Configuration (config/config.php)
{
    "instanceid": "***REMOVED SENSITIVE VALUE***",
    "passwordsalt": "***REMOVED SENSITIVE VALUE***",
    "secret": "***REMOVED SENSITIVE VALUE***",
    "trusted_domains": [
        "cloud.rekorder.org"
    ],
    "datadirectory": "***REMOVED SENSITIVE VALUE***",
    "dbtype": "mysql",
    "version": "21.0.2.0",
    "overwrite.cli.url": "http:\/\/cloud.rekorder.org",
    "dbname": "***REMOVED SENSITIVE VALUE***",
    "dbhost": "***REMOVED SENSITIVE VALUE***",
    "dbport": "",
    "dbtableprefix": "oc_",
    "mysql.utf8mb4": true,
    "dbuser": "***REMOVED SENSITIVE VALUE***",
    "dbpassword": "***REMOVED SENSITIVE VALUE***",
    "installed": true,
    "updater.release.channel": "stable",
    "memcache.local": "\\OC\\Memcache\\APCu",
    "maintenance": false,
    "data-fingerprint": "11bd4c43db46260d550ca15af9437513",
    "mail_smtpmode": "smtp",
    "mail_smtpsecure": "ssl",
    "mail_sendmailmode": "smtp",
    "mail_from_address": "***REMOVED SENSITIVE VALUE***",
    "mail_domain": "***REMOVED SENSITIVE VALUE***",
    "mail_smtpauthtype": "LOGIN",
    "mail_smtpauth": 1,
    "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
    "mail_smtpport": "465",
    "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
    "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
    "theme": "",
    "loglevel": 2,
    "app_install_overwrite": [
        "issuetemplate"
    ]
}

Are you using external storage, if yes which one: local/smb/sftp/...

Are you using encryption:

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...

Client configuration

Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36

@maxrekorder maxrekorder changed the title Can't open PDF file in viewer when filename is containing a space (' ') in shared folder Can't open PDF file in viewer when filename or foldername is containing a space (' ') May 15, 2021
@ynjo
Copy link

ynjo commented May 15, 2021

Same issue here

@skjnldsv
Copy link
Member

@beardhatcode, can you reproduce the double encoding?

@beardhatcode
Copy link
Contributor

Yes, I was able to reproduced it last week

@beardhatcode
Copy link
Contributor

(I tested in Firefox btw)

@stefanroesler
Copy link

We also have the problem with version 21.0.2

Tested in Firefox and Chrome, also in the backend nginx or Apache2, unfortunately always the same error. As soon as the file has a space, it does not open it. It works fine without spaces.

@ib-mlatin
Copy link

I'm having this same issue with version 21.0.2. It was working perfectly in 21.0.1. Using SMB shares, but it also fails with the "test" files that Nextcloud makes for new users. See images below:

chrome_2021-05-20_12-23-28

chrome_2021-05-20_12-25-05

@obrb
Copy link

obrb commented May 20, 2021

Actually anything that generates a % in the URL. like Umlauts, #, ?, spaces etc... causes this error. A file named "#PDF mit Abständen und Umlauten.pdf" produces the following error message:

Message: Missing PDF "https://cloud.mydomain.tld/remote.php/dav/files/user/%2523PDF%2520mit%2520Abst%25C3%25A4nden%2520und%2520Umlauten.pdf".

This also happens if the name of a parent folder contains any of these characters or spacing.

@Zniets
Copy link

Zniets commented May 20, 2021

Did you all use php8?

@ib-mlatin
Copy link

Did you all use php8?

No, I'm using the below PHP version:

PHP 7.4.18 (cli) (built: May  3 2021 11:27:06) ( NTS )

@szaimen
Copy link
Collaborator

szaimen commented May 20, 2021

I have the same issue now with NC20.0.10 and NC21.0.2
PHP7.4 here

@xpfgsyb
Copy link

xpfgsyb commented May 20, 2021

Did you all use php8?

No, NC 21.0.2 with the following PHP version here:
PHP 7.3.27-1~deb10u1 (cli) (built: Feb 13 2021 16:31:40) ( NTS )

@fenvarien
Copy link

Here we have the same issue with NC 21.0.2 (PHP 7.4.18). To help the students of my school tomorrow, I switched to OnlyOffice as the default PDF viewer as a workaround. But I wonder how this bug could slip through with the release of 21.0.2.
Is it possible to revert to an older version of pdfviewer?

@szaimen
Copy link
Collaborator

szaimen commented May 20, 2021

cc @nextcloud/server-triage

@JazMTaz
Copy link

JazMTaz commented May 21, 2021

Same issue here

Nextcloud 20.0.10

Operating System: | Linux 5.4.0-1035-raspi aarch64
Memory: | 7.63 GB

Nginx version: nginx/1.18.0 (Ubuntu)

Database
Type: mysql
Version: 10.3.29

PHP
Version: 7.4.3

@pierreGLV9
Copy link

PHP 7.4.9
MariaDB 10.3.24
Nexcloud 21.0.1 : Everythink perfectly worked
Nextcloud 21.0.2 : I encountered the same issue with PDF files, unable to view the files with spaces in name...

@chrissi55
Copy link

Same here with PHP 7.4.18 -> NC 21.0.2

Obviously it is not nexcessary that the PDF Filename contains Spaces - one space in the whole path is causing the error

So not just ../My Name.PDF but also /this.is/my path/to.the.file/My-Name.PDF causes the error

@rakekniven rakekniven added the bug label May 21, 2021
@beardhatcode
Copy link
Contributor

beardhatcode commented May 21, 2021

@skjnldsv , I think it will likely suffice to remove the encode here:

encodedDavPath += '/' + encodeURIComponent(pathSections[i])

The davpath that is returned by viewer is now already "safe" so there is no need to encode it again. I might try this out tonight.

@Zniets
Copy link

Zniets commented May 21, 2021

How can I test this?

@beardhatcode
Copy link
Contributor

beardhatcode commented May 21, 2021

@Zniets, you could edit that file and change the aforementioned line to encodedDavPath += pathSections[i] and compile the new js. And see if this works.

Alternatively, I you don't want to compile, you could edit apps/files_pdfviewer/js/files_pdfviewer-main.js and change

!==i[a]&&(c+="/"+encodeURIComponent(i[a]));return t&&(c=i[0]+"//"+i[2]+c),c}}

to

!==i[a]&&(c+="/"+i[a]);return t&&(c=i[0]+"//"+i[2]+c),c}}

Or even simpler: Just replace
apps/files_pdfviewer/js/files_pdfviewer-main.js on your instance with this file from the PR that should fix the issue.

If you try this out, could you report back if that solved the issue? Thanks 🙂

@DmDS
Copy link

DmDS commented May 21, 2021

Alternatively, I ou don't want to compile, you could edit apps/files_pdfviewer/js/files_pdfviewer-main.js and change....

it helped, thanks!

@beardhatcode
Copy link
Contributor

@DmDS, do you mean that the proposed edit resolved the issue completely?

@DmDS
Copy link

DmDS commented May 21, 2021

@DmDS, do you mean that the proposed edit resolved the issue completely?

yes)

@Zniets
Copy link

Zniets commented May 21, 2021

@Zniets, you could edit that file and change the aforementioned line to encodedDavPath += pathSections[i] and compile the new js. And see if this works.

Alternatively, I you don't want to compile, you could edit apps/files_pdfviewer/js/files_pdfviewer-main.js and change

!==i[a]&&(c+="/"+encodeURIComponent(i[a]));return t&&(c=i[0]+"//"+i[2]+c),c}}

to

!==i[a]&&(c+="/"+i[a]);return t&&(c=i[0]+"//"+i[2]+c),c}}

If you try this out, could you report back if that solved the issue? Thanks 🙂

This worked for me

@beardhatcode
Copy link
Contributor

Thanks for testing this out @DmDS and @Zniets 👍

@mvvvmd
Copy link

mvvvmd commented May 21, 2021

I can confirm it works again with the change, after clearing the browser cache.

@janvier-vip
Copy link

@beardhatcode confirmed it fixed the problem. thanks a lot. :)

@sinichi19
Copy link

sinichi19 commented May 24, 2021

Alternatively, I you don't want to compile, you could edit apps/files_pdfviewer/js/files_pdfviewer-main.js and change

!==i[a]&&(c+="/"+encodeURIComponent(i[a]));return t&&(c=i[0]+"//"+i[2]+c),c}}

to

!==i[a]&&(c+="/"+i[a]);return t&&(c=i[0]+"//"+i[2]+c),c}}

If you try this out, could you report back if that solved the issue? Thanks 🙂

confirmed fixed,

after update to 20.0.10 cant open pdf, but after i tried this is now working .

Thank You Sir

@maxrekorder
Copy link
Author

Thank you so much for the help. The bugfix works!

In the future it would be nice if the functions of the app were tested before a new update is rolled out.

@beardhatcode
Copy link
Contributor

The fix for this issue is not yet merged, to help others find this out I'll reopen the issue

@rogercreagh
Copy link

Any idea of timescale when this will be available as a release for NC20.x (currently on v2.0.1) that can be installed as an update from within NC for those of us who don't have sudo access to the server? Its a right pain at present - we've had to switch pdf viewing to OpenOffice and it is so slooow. (we have loads of pdf files and folder names with spaces and all was good till we updated to NC20.x this week)

@aleskomarek
Copy link

This fix repair opening my own PDF files, but does not solve opening shared PDF files.

@beardhatcode
Copy link
Contributor

@aleskomarek did you replace the entire file or just the did you just do the mini edit?

@aleskomarek
Copy link

@aleskomarek did you replace the entire file or just the did you just do the mini edit?

without file replacement or file edition

@Oriann
Copy link

Oriann commented May 25, 2021

@aleskomarek wait you said that without any fix you have working pdf viewer from cloud but not from shared link?

@aleskomarek
Copy link

@aleskomarek wait you said that without any fix you have working pdf viewer from cloud but not from shared link?

sorry for my inaccuracy, i uploaded PDF file to my account and with this fix I opened this file in buildin PDF viewer, but when I shared this file to another user and this user opens this shared file in buildin PDF viewer problem persists - file is missing

@beardhatcode
Copy link
Contributor

@aleskomarek , could you ask that other user to clear their browser cache? They are likely still using the old code.

@aleskomarek
Copy link

@aleskomarek wait you said that without any fix you have working pdf viewer from cloud but not from shared link?

sorry for my inaccuracy, i uploaded PDF file to my account and with this fix I opened this file in buildin PDF viewer, but when I shared this file to another user and this user opens this shared file in buildin PDF viewer problem persists - file is missing

I'm have shared folder to another user and I moved a PDF file to this shared folder. Another user has problem with opening this PDF file in buildin PDF viewer. In NC version 21.0.1 this was ok.

@aleskomarek
Copy link

@aleskomarek , could you ask that other user to clear their browser cache? They are likely still using the old code.

You are right. Now this is also functional over shared folder/file. Trouble was really in user's web browser. After restart browser and clear cache this is ok. I apologize for my fault.

backportbot-nextcloud bot pushed a commit that referenced this issue May 25, 2021
The errors that required encodeURIComponent in the past have been
mittigated by the following commit on nextcloud viewer.

nextcloud/viewer@02e1b1a

The code with hasScheme may be removed, viewer now returns a full
properly encoded URI thanks to the work done in nextcloud-router

fixes #381

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>
backportbot-nextcloud bot pushed a commit that referenced this issue May 25, 2021
The errors that required encodeURIComponent in the past have been
mittigated by the following commit on nextcloud viewer.

nextcloud/viewer@02e1b1a

The code with hasScheme may be removed, viewer now returns a full
properly encoded URI thanks to the work done in nextcloud-router

fixes #381

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>
npmbuildbot-nextcloud bot pushed a commit that referenced this issue May 25, 2021
The errors that required encodeURIComponent in the past have been
mittigated by the following commit on nextcloud viewer.

nextcloud/viewer@02e1b1a

The code with hasScheme may be removed, viewer now returns a full
properly encoded URI thanks to the work done in nextcloud-router

fixes #381

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
npmbuildbot-nextcloud bot pushed a commit that referenced this issue May 25, 2021
The errors that required encodeURIComponent in the past have been
mittigated by the following commit on nextcloud viewer.

nextcloud/viewer@02e1b1a

The code with hasScheme may be removed, viewer now returns a full
properly encoded URI thanks to the work done in nextcloud-router

fixes #381

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
@RodSeq
Copy link

RodSeq commented May 27, 2021

I confirm I had the same issue after upgrading my instance to NC 21.0.2, now solved with your temporary fix replacing the file "apps/files_pdfviewer/js/files_pdfviewer-main.js" + restarting my browser. Many thanks for your temporary fix for that very critical issue !

Before that a new NC stable version including your fix is released, I suggest that Nextcloud removes 21.0.2 from the "stable" release channel, avoiding that other NC Users experience that critical bug.

@Oriann
Copy link

Oriann commented May 27, 2021

@RodSeq totally agree, some users might not be able to fix that easily because lack of experience. Some users may not be even able to access this file location cos of hosting limits.

@solracsf
Copy link
Member

Please note that "stable" doesn't mean "bug free".
CI tests doesn't cover ALL possible scenarios, in any software.

Last but not least, "stable" also doesn't mean "apply it blindly". 😉
Even more on critical (enterprise) environments.

@nextcloud nextcloud locked as resolved and limited conversation to collaborators May 27, 2021
@skjnldsv skjnldsv unpinned this issue Jun 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.