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

Fix for issue 6487: Opening BibTex file (doubleclick) from Folder with spaces not working #7551

Merged
merged 14 commits into from
Mar 19, 2021

Conversation

XDZhelheim
Copy link
Contributor

@XDZhelheim XDZhelheim commented Mar 18, 2021

Fixes #6487

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

Video:

fix6487.mp4

Use D:\TEST\test whitespace.bib as an example.

Double-click it, and I got errors in console as the following:

Error opening file 'D:\TEST\test': Could not find a suitable import format.
Error opening file 'whitespace.bib': Could not find a suitable import format.
21:41:53.032 [JabRef - Remote Listener Server on port 6050] ERROR org.jabref.logic.importer.OpenDatabase - Error: File not found

Therefore, the path was regarded as two files: D:\TEST\test and whitespace.bib.

Start from org.jabref.logic.importer.OpenDatabase to backtrack the dataflow:

Class Method Variable
OpenDatabase loadDatabase fileToOpen
ArgumentProcessor importAndOpenFiles aLeftOver
JabRefCLI constructor args
ArgumentProcessor constructor args
JabRefMessageHandler handleCommandlineArguments message
RemoteListenerServer handleMessage argument
RemoteListenerServer run input.getValue()
Protocol receiveMessage argument

Use logger to print the variable argument:

if (argument instanceof String[]) {
    LOGGER.info(Arrays.toString((String[]) argument));
}

And I got:

21:41:53.024 [JabRef - Remote Listener Server on port 6050] INFO  org.jabref.logic.remote.shared.Protocol - [D:\TEST\test, whitespace.bib]

So I think the problem is that when passing the argument D:\TEST\test whitespace.bib, it will be considered as two arguments because there is a whitespace that serves as a delimiter.

I noticed that @zongxian said that a path containing Chinese characters would cause the same error. So the problem is not just related to delimiter, probably about text encoding.

Therefore I encoded the arguments in RemoteClient.sendCommandLineArguments and decoded them in Protocol.receiveMessage.

Then I created a binary and tested. Now it works well on my computer (Windows 10 1909).

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your detailed analysis! The fix looks good to me.

The linked issue also mentions that double clicking a file without having jabref open doesn't work sometimes (if I got the gist right by skimming it). I guess this is not fixed with this PR, right?

@@ -52,7 +54,13 @@ public boolean ping() {
*/
public boolean sendCommandLineArguments(String[] args) {
try (Protocol protocol = openNewConnection()) {
protocol.sendMessage(RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS, args);

String[] encodedArgs = args.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Can you please put this addition in the protocol.sendMessage so that only the protocol has to worry about decoding/encoding. Also please add a short comment explaining why we need to encode. Thanks!

created a new test in RemoteCommunicationTest
@XDZhelheim
Copy link
Contributor Author

Thanks for your acknowledgement!

I moved it to Protocol.sendMessage and added some comments.

Besides, I created a new test case in RemoteCommunicationTest.


As @RickVandoorne mentioned:

  • If I double click on a .bib file while JabRef is NOT running then JabRef opens (it no longer gives me the error message). However, it does not open the file which I double clicked.
  • If I double click on a .bib file while JabRef is running it opens a new library called "untitled" but not the file I double clicked.
  • If I open JabRef first and then open a file using "File" → "Open library" it works fine.

I tested these three ways to open a .bib file, got no error.

Double click while JabRef not running:
https://user-images.githubusercontent.com/57553691/111728161-47c5e680-88a7-11eb-81d2-ddd56253b3da.mp4

Double click while JabRef running:
Video above.

"Open library":

open.library.mp4

final String[] message = new String[]{"D:\\T EST\\测试te st.bib"};

// will be encoded as "D%3A%5CT+EST%5C%E6%B5%8B%E8%AF%95te+st.bib"
client.sendCommandLineArguments(message.clone());

verify(server).handleCommandLineArguments(message);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering whether this test case is appropriate. Not so sure about how to write a test about socket communication.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's hard to test this. I think, your added test is fine.

@@ -51,7 +51,7 @@ void pingReturnsTrue() throws IOException, InterruptedException {
void commandLineArgumentSinglePassedToServer() {
final String[] message = new String[]{"my message"};

client.sendCommandLineArguments(message);
client.sendCommandLineArguments(message.clone());
Copy link
Member

Choose a reason for hiding this comment

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

I would move the clone call to the sendMessage method. It's usually a good practice to not modify parameters passed to a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you for your advice!

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

thanks for the fix! LGTM as well

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Thanks again for your contribution! Looking forward to your next PR 🚀

@tobiasdiez tobiasdiez merged commit 049acb9 into JabRef:master Mar 19, 2021
Siedlerchr added a commit that referenced this pull request Mar 28, 2021
* upstream/master: (191 commits)
  Fix for issue 7416: font size of the preferences dialog does not update with the rest of the GUI. (#7509)
  Fix school/instituation is printed twice (#7574)
  Dsiable notarisation until we hae an account for JabRef e.V. (#7572)
  Fix citation keys unintentionally being overwritten on import (#7443)
  Fix AuthentificationPlugin not declared in mergedModule (#7570)
  Suggestions for changes in caching latex free authors (#7301)
  Add simple Unit Tests (#7542)
  Fix drag and drop into empty library (#7555)
  Bump richtextfx from 0.10.4 to 0.10.6 (#7563)
  Bump pdfbox from 2.0.22 to 2.0.23 (#7561)
  Bump org.eclipse.jgit (#7560)
  Bump fontbox from 2.0.22 to 2.0.23 (#7562)
  Bump guava from 30.1-jre to 30.1.1-jre (#7564)
  Bump xmpbox from 2.0.22 to 2.0.23 (#7565)
  Bump hmarr/auto-approve-action from v2.0.0 to v2.1.0 (#7566)
  Add gource (#7193)
  UI: Fix for group icon (#7552)
  Fix for issue 6487: Opening BibTex file (doubleclick) from Folder with spaces not working (#7551)
  add ability to insert arxivId (#7549)
  Fixed missing trigger for linked file operations (#7548)
  ...
@sauliusg sauliusg mentioned this pull request Mar 28, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening BibTex file (doubleclick) from Folder with spaces not working
3 participants