PDF Downloader downloads HTML source code instead if no access #7474
Conversation
|
Thanks for your contribution, this is a good first step. Please have a look at the checkstlye/reviewdog style checker. |
Adds ignore parameter to mime type and notify the user if the file downloaded is HTML.
Use Localization when writing messages in the status bar.
replace StringUtils::substringBefore with String::substring
Add test ensuring the UI warns the user if they download a linked HTML file (i.e. a web page).
The test checks the resulting file type when downloading a HTML file.
Add check to only process the mimeType if an ';' exists inside the string
Tests that mime type with parameter value is parsed correctly to exclude the parameter.
Sets a new system-wide cookie manager if there is none, and sets the cookie policy to ACCEPT_NONE after each test.
Clean up code styling according to JabRef style guidelines.
08486f2 to
5ec83b6
Compare
Siedlerchr
left a comment
There was a problem hiding this comment.
Thanks for your contribution and also for the tests, just a minor remark regarding the preferences mocking
|
Thanks for a great first time experience regarding open source. Our course is now over and the project has been presented. I hope this patch has been helpful in order to improve your open source project and i wish you good luck in the future! From @binsu-kth , @grundb , @kittytinythai , @keivanm & @kaniyi from KTH (Royal Institute of Technology) course DD2480 . |
| // Structure taken from deleteWhenDialogCancelledReturnsFalseAndDoesNotRemoveFile method | ||
| @Test | ||
| void downloadHtmlFileCausesWarningDisplay() throws MalformedURLException { | ||
| Globals.prefs = JabRefPreferences.getInstance(); // required for task execution |
There was a problem hiding this comment.
You don't need that assignment
| ExternalFileTypes externalFileTypes = ExternalFileTypes.getInstance(); | ||
| Optional<ExternalFileType> test = externalFileTypes.getExternalFileTypeByMimeType("text/html; charset=UTF-8"); | ||
| Globals.prefs = jabRefPreferences.getInstance(); // required for task execution | ||
| ExternalFileTypes externalFileTypesInstance = externalFileType.getInstance(); |
There was a problem hiding this comment.
same as above and you don't need to call getInstance , the mock already creates an instance for you
|
Thanks for your contribution, it would be really nice if you could address the small changes in the test so that we can merge. |
calixtus
left a comment
There was a problem hiding this comment.
Hi folks, thank you for your contribution so far. I have one more important question and bit nitpicking about code / comment style.
Good look with your studies, I hope you like working with JabRef. JabRef is a project of some open source enthusiasts, who like to share their interest in open source with other people and especially to help students learn about free software. We are always happy, if someone decides to put some time and energy in our common project.
| dialogService.notify(Localization.lang("Downloaded website as an HTML file.")); | ||
| LOGGER.debug("Downloaded website {} as an HTML file at {}", linkedFile.getLink(), destination); |
There was a problem hiding this comment.
Is this really the error message, a user can understand?
As I understand this PR, the user tries to download a not accessible PDF file. This is not possible, so JabRef downloads the website showing "not allowed" or something.
But the user does not know this, but is only shown: "Downloaded website as an HTML file."
I guess the right error message would be something like: "Problem accessing PDF file, unexpected download result. Please try manually."
There was a problem hiding this comment.
The thing is you can also link a html file and really want to download the html. Thus it is not always a mistake to download html. Maybe it's ok to ignore this problematic (except if the user sets the file type to HTML)?
Apart from this, I also like the suggestion of @Krzmbrzl in #7452
My suggestion for a mitigation would be to check the downloaded file and if it starts with plain text , then assume the download has failed and remove the "PDF" again (restoring the file link with the download URL in JabRef).
to keep the link in case the download produced a html file. In this case, the user can activate his university vpn/proxy and simply try again.
| Pattern warningPattern = Pattern.compile(".*HTML.*", Pattern.CASE_INSENSITIVE); | ||
| verify(dialogService, atLeastOnce()).notify(matches(warningPattern)); |
There was a problem hiding this comment.
Can't this be simplified somehow to a test for a static string (I believe the tests are running in english localization by default) instead of matching a regex? Millisecs do not count if it's just one test, but we have some more. 😅
| // Structure taken from deleteWhenDialogCancelledReturnsFalseAndDoesNotRemoveFile method | ||
| @Test | ||
| void downloadHtmlFileCausesWarningDisplay() throws MalformedURLException { | ||
| // From BibDatabaseContextTest::setUp | ||
| when(filePreferences.shouldStoreFilesRelativeToBib()).thenReturn(true); | ||
| when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); // used in other tests in this class | ||
| when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); // used in movesFileWithFileDirPattern at MoveFilesCleanupTest.java |
There was a problem hiding this comment.
If you like to comment something for the reviewer, you can comment on your own PRs in the github-ui. But please check twice, if a comment made in the source really has some long lasting use. Otherwise it's just polluting the codebase.
These comments here seem to be superfluous.
| // Tests if added parameters to mimeType gets parsed to correct format. | ||
| @Test | ||
| void mimeTypeStringWithParameterIsReturnedAsWithoutParameter() { |
There was a problem hiding this comment.
The comment here seems just to describe in other words, what the name of the test method implies, so probably unnecessary too.
|
It would be really nice if you could address the small comments so we can finally merge this |
Adds ignore parameter to
mimeTypeand notify the user if the downloaded file is of HTML type, fixes #7452.In the method
ExternalFileTypes::getExternalFileTypeByMimeType, we added a feature to remove the parameters partof the
mimeType, this is allowed in mimeType-specification link. The previous code didn't consider the parameter part of the mimeType, thus not conforming to the correct enum type inStandardExternalFileType.java.We also added a feature to notify the user if the downloaded link is a HTML file, via the "status bar", because the user might think they have downloaded a PDF while this isn't the case.
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)Screenshot 1: The downloaded file from the issue example is downloaded as a HTML file instead of a HTML-file disguised as a PDF-file.
Screenshot of importing the article in the issue
Screenshot of notification/warning that the link is downloaded as an HTML file after the import is complete
Screenshot showing that the file downloaded is now a local HTML file