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

Remove encodeURI code #384

Merged
merged 1 commit into from
May 25, 2021
Merged

Remove encodeURI code #384

merged 1 commit into from
May 25, 2021

Conversation

beardhatcode
Copy link
Contributor

@beardhatcode beardhatcode commented May 21, 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


ℹ️ You can teporarily apply this patch by replacing
apps/files_pdfviewer/js/files_pdfviewer-main.js on your instance with this file from this PR. Clear your browser's cache and try to open pdfs.

That should fix the issue. Please leave feedback if that does or doesn't work for you.

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>
@beardhatcode
Copy link
Contributor Author

beardhatcode commented May 21, 2021

I tested this for local files with the name "2020_opgave 🪓 NL .pdf" in a folder that also contained an emoji in its name

Someone still needs to test if federation works. But it should, the previewer that gets called with the full URI:

http://localhost:8080/apps/files_pdfviewer/?file=http://localhost:8080/remote.php/dav/files/root/fwefw%202020_opgave%20%F0%9F%AA%93%20NL%20.pdf/2020_opgave%20%F0%9F%AA%93%20NL%20.pdf

@beardhatcode
Copy link
Contributor Author

/backport to stable21

@beardhatcode
Copy link
Contributor Author

/backport to stable20

@beardhatcode
Copy link
Contributor Author

I was wondering if there is a way to ship updates to this app outside a release of Nextcloud, and if that is something that would be appropriate for this issue?

@jacotec
Copy link

jacotec commented May 22, 2021

This bug breaks the PDF viewer in all NC 21.0.2 installations. I guess one of the most used features. I've applied the hotfix from @beardhatcode manually, but in the interest of all NC users this update should be pushed ASAP and not only with the next NC release. Just my 2 cent.

However I wonder how this did pass release testing ...

@solracsf
Copy link
Member

@MorrisJobke maybe this is something you can make a quick release? 🤔

@MorrisJobke
Copy link
Member

cc @LukasReschke

Copy link
Member

@LukasReschke LukasReschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks for putting up a diff, much appreciated.

@skjnldsv
Copy link
Member

I was wondering if there is a way to ship updates to this app outside a release of Nextcloud

No unfortunately :(

@skjnldsv
Copy link
Member

@beardhatcode maybe it would be worth adding one or two cypress tests here as well, if you have time?

Thanks a lot for all you did and do 🤗 🚀

@skjnldsv skjnldsv merged commit 1d3c5de into master May 25, 2021
@skjnldsv skjnldsv deleted the fix/encoding branch May 25, 2021 14:35
Comment on lines -40 to -70
encodedDavPath() {
const hasScheme = this.davPath.indexOf('://') !== -1

if (this.davPath.indexOf(generateUrl('/s/')) === 0) {
const host = window.location.protocol + '//' + window.location.host
const url = new URL(hasScheme ? this.davPath : host + this.davPath)
const path = this.filename.replace(this.basename, '')
url.searchParams.set('path', path)
url.searchParams.set('files', this.basename)
return hasScheme ? url.toString() : url.toString().substr(host.length)
}

const pathSections = this.davPath.split('/')

// Ignore scheme and domain in the loop (note that the scheme
// delimiter, "//", creates an empty section when split by "/").
const initialSection = hasScheme ? 3 : 0

let encodedDavPath = ''
for (let i = initialSection; i < pathSections.length; i++) {
if (pathSections[i] !== '') {
encodedDavPath += '/' + encodeURIComponent(pathSections[i])
}
}

if (hasScheme) {
encodedDavPath = pathSections[0] + '//' + pathSections[2] + encodedDavPath
}

return encodedDavPath
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good rid of this legacy code! 🧹

@skjnldsv

This comment has been minimized.

@skjnldsv

This comment has been minimized.

@skjnldsv
Copy link
Member

/backport to stable20

@skjnldsv
Copy link
Member

/backport to stable21

@livier
Copy link

livier commented May 27, 2021

The patch worked here, thanks.

@jdaviescoates
Copy link

Many thanks of this fix, but how long will we need to wait to this get into an actual Nextcloud release? I'm fairly flabbergasted that 21.0.2 was released without basic PDF support! Really very disappointing 😞

@LukasReschke
Copy link
Member

Many thanks of this fix, but how long will we need to wait to this get into an actual Nextcloud release?

The next regular release is scheduled for 2021-07-01 (https://github.com/nextcloud/server/wiki/Maintenance-and-Release-Schedule)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants