Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Fix #10554, #11059: remove check for .pdf in URL extensions, prefer response headers #13587

Merged
merged 3 commits into from
Jul 18, 2018

Conversation

humphd
Copy link

@humphd humphd commented Mar 24, 2018

This fixes the issue in Brave where URLs that contain .pdf in a file's extension are automatically assumed to be PDF resources, and get loaded with PDF.js. This turns out to be problematic for sites like Dropbox or GitHub, which allow user generated content to be named with a .pdf extension, but served as HTML (e.g., with a custom UI wrapped around it).

In debugging this, I found that the bug was introduced in #8366 as a partial fix for #8364. The underlying issue has since been mostly fixed in other code, and all I needed to do was remove the temporary URL rewriting code in order to let requests get properly inspected. I've tested with URLs and cases from the original bug, as well as current ones, and all seem to work as expected.

I've also attempted to add a regression test for the case of a .pdf URL being served with text/html. The underlying test server didn't support overriding content-type, so I also included a fix to allow it. I realize you might want this done another way, or not at all. I would have upstreamed a fix to node-static, but it seems mostly unmaintained. I'm not familiar with all of your test code, so please let me know if I can improve or correct anything I've done.

Finally, I've written this up as a walkthrough for my students, who are learning open source development. Quite a few of them are either working on Brave, or hoping to, so I wanted to give them some guidance by fixing a bug myself and writing about the process. You can see that at https://github.com/humphd/browser-laptop/tree/good-first-experience-issue-10554#walkthrough-fixing-a-bug-in-the-brave-browser. I'll show them this next week.

@@ -278,6 +279,20 @@ describe('frame tests', function () {
.url(url)
.waitForVisible('#viewerContainer')
})

it('loads HTML properly despite having .pdf extension', function * () {
Copy link
Member

Choose a reason for hiding this comment

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

thanks for adding a test! unfortunately our automated webdriver test environment is totally broken at the moment, so instead i ran the custom server and manually loaded the .pdf HTML file. confirmed that it is broken in latest release and fixed with this PR.

diracdeltas
diracdeltas previously approved these changes Mar 26, 2018
@NejcZdovc NejcZdovc added this to the Completed work milestone Mar 27, 2018
@alexwykoff alexwykoff modified the milestones: Completed work, 0.25.x Apr 10, 2018
@diracdeltas
Copy link
Member

@humphd this needs a rebase since some of the urlutil tests were moved into a different file

@humphd
Copy link
Author

humphd commented Apr 24, 2018

@diracdeltas noted. I'll push an update next week. Thanks for the review.

@humphd
Copy link
Author

humphd commented Apr 30, 2018

Rebased and updated urlutil test change.

@SilverPuppy
Copy link

Is this abandoned?

@humphd
Copy link
Author

humphd commented Jul 7, 2018 via email

@diracdeltas
Copy link
Member

@humphd it needs a rebase actually. once that's done i'll move the milestone to 0.24 and merge

@humphd
Copy link
Author

humphd commented Jul 13, 2018

@diracdeltas, @bsclifton I've rebased again, and this should be good to go now. Let me know if you need me to do more, or something different.

yield this.app.client
.tabByIndex(0)
.url(url)
.waitForUrl(url)
Copy link
Member

Choose a reason for hiding this comment

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

this test needs a .windowByUrl(Brave.browserWindowUrl) here to switch from the page context into the Brave window context or else it fails because there's no activeTabTitle component found.

Copy link
Author

Choose a reason for hiding this comment

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

@diracdeltas OK, I've added this in 0224cd6.

@diracdeltas diracdeltas merged commit 12650d7 into brave:master Jul 18, 2018
diracdeltas added a commit that referenced this pull request Jul 18, 2018
 Fix #10554, #11059: remove check for .pdf in URL extensions, prefer response headers
@diracdeltas
Copy link
Member

master: 12650d7
0.24.x: a02742c

thanks @humphd !!

@humphd
Copy link
Author

humphd commented Jul 19, 2018

Excellent, thanks @diracdeltas, and thanks for the reviews. Glad to contribute, love Brave. Hope I can do more.

bsclifton pushed a commit that referenced this pull request Jul 23, 2018
 Fix #10554, #11059: remove check for .pdf in URL extensions, prefer response headers
@bsclifton
Copy link
Member

Uplifted to 0.23.x with 34329d2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants