Skip to content

PDF Downloader downloads HTML source code instead if no access #7474

Merged
Siedlerchr merged 18 commits into
JabRef:masterfrom
DD2480-2021-group-22:fix-for-issue-7452
Mar 14, 2021
Merged

PDF Downloader downloads HTML source code instead if no access #7474
Siedlerchr merged 18 commits into
JabRef:masterfrom
DD2480-2021-group-22:fix-for-issue-7452

Conversation

@binsu-kth

@binsu-kth binsu-kth commented Feb 28, 2021

Copy link
Copy Markdown
Contributor

Adds ignore parameter to mimeType and 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 part
of 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 in StandardExternalFileType.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.

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

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.

image

Screenshot of importing the article in the issue

Screenshot from 2021-03-03 14-57-15

Screenshot of notification/warning that the link is downloaded as an HTML file after the import is complete

Screenshot from 2021-03-03 14-57-25

Screenshot showing that the file downloaded is now a local HTML file

Screenshot from 2021-03-03 14-58-34

@Siedlerchr

Copy link
Copy Markdown
Member

Thanks for your contribution, this is a good first step. Please have a look at the checkstlye/reviewdog style checker.

@binsu-kth binsu-kth marked this pull request as ready for review March 4, 2021 15:26
@binsu-kth binsu-kth marked this pull request as draft March 4, 2021 15:27
binsu-kth and others added 13 commits March 4, 2021 19:05
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.
@grundb grundb force-pushed the fix-for-issue-7452 branch from 08486f2 to 5ec83b6 Compare March 4, 2021 18:16
@binsu-kth binsu-kth marked this pull request as ready for review March 4, 2021 18:32
Comment thread src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java Outdated

@Siedlerchr Siedlerchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution and also for the tests, just a minor remark regarding the preferences mocking

@Siedlerchr Siedlerchr added the status: changes-required Pull requests that are not yet complete label Mar 4, 2021
@binsu-kth

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't need that assignment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed.

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above and you don't need to call getInstance , the mock already creates an instance for you

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@Siedlerchr

Copy link
Copy Markdown
Member

Thanks for your contribution, it would be really nice if you could address the small changes in the test so that we can merge.

@Siedlerchr Siedlerchr added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Mar 7, 2021

@calixtus calixtus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +451 to +452
dialogService.notify(Localization.lang("Downloaded website as an HTML file."));
LOGGER.debug("Downloaded website {} as an HTML file at {}", linkedFile.getLink(), destination);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +201 to +202
Pattern warningPattern = Pattern.compile(".*HTML.*", Pattern.CASE_INSENSITIVE);
verify(dialogService, atLeastOnce()).notify(matches(warningPattern));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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. 😅

Comment on lines +183 to +189
// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +275 to +277
// Tests if added parameters to mimeType gets parsed to correct format.
@Test
void mimeTypeStringWithParameterIsReturnedAsWithoutParameter() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The comment here seems just to describe in other words, what the name of the test method implies, so probably unnecessary too.

@tobiasdiez tobiasdiez added the status: changes-required Pull requests that are not yet complete label Mar 10, 2021
@Siedlerchr

Copy link
Copy Markdown
Member

It would be really nice if you could address the small comments so we can finally merge this

@Siedlerchr Siedlerchr merged commit 7bd9c0d into JabRef:master Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: changes-required Pull requests that are not yet complete status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF Downloader downloads HTML source code instead if no access

7 participants