Skip to content

Commit

Permalink
Fix for issue 6487: Opening BibTex file (doubleclick) from Folder wit…
Browse files Browse the repository at this point in the history
…h spaces not working (#7551)

* Fix #7416

* sync with origin

* backtracking file path argument

who invoked the method sendMessage(type=SEND_COMMAND_LINE_ARGUMENTS) when double-clicking

* fix #6487 (draft)

* fix

* moved encoding to sendMessage
created a new test in RemoteCommunicationTest

* move clone to sendMessage
  • Loading branch information
XDZhelheim committed Mar 19, 2021
1 parent f1d3003 commit 049acb9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where columns shrink in width when we try to enlarge JabRef window. [#6818](https://github.com/JabRef/jabref/issues/6818)
- We fixed an issue where Content selector does not seem to work for custom fields. [#6819](https://github.com/JabRef/jabref/issues/6819)
- We fixed an issue in which a linked online file consisting of a web page was saved as an invalid pdf file upon being downloaded. The user is now notified when downloading a linked file results in an HTML file. [#7452](https://github.com/JabRef/jabref/issues/7452)
- We fixed an issue where opening BibTex file (doubleclick) from Folder with spaces not working. [#6487](https://github.com/JabRef/jabref/issues/6487)

### Removed

Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/jabref/logic/remote/shared/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import javafx.util.Pair;

Expand Down Expand Up @@ -39,7 +42,19 @@ public void sendMessage(RemoteMessage type) throws IOException {

public void sendMessage(RemoteMessage type, Object argument) throws IOException {
out.writeObject(type);
out.writeObject(argument);

// encode the commandline arguments to handle special characters (eg. spaces and Chinese characters)
// related to issue #6487
if (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS) {
String[] encodedArgs = ((String[]) argument).clone();
for (int i = 0; i < encodedArgs.length; i++) {
encodedArgs[i] = URLEncoder.encode(encodedArgs[i], StandardCharsets.UTF_8);
}
out.writeObject(encodedArgs);
} else {
out.writeObject(argument);
}

out.write('\0');
out.flush();
}
Expand All @@ -50,6 +65,13 @@ public Pair<RemoteMessage, Object> receiveMessage() throws IOException {
Object argument = in.readObject();
int endOfMessage = in.read();

// decode the received commandline arguments
if (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS) {
for (int i = 0; i < ((String[]) argument).length; i++) {
((String[]) argument)[i] = URLDecoder.decode(((String[]) argument)[i], StandardCharsets.UTF_8);
}
}

if (endOfMessage != '\0') {
throw new IOException("Message didn't end on correct end of message identifier. Got " + endOfMessage);
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ void commandLineArgumentMultiLinePassedToServer() {

verify(server).handleCommandLineArguments(message);
}

@Test
void commandLineArgumentEncodingAndDecoding() {
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);

verify(server).handleCommandLineArguments(message);
}
}

0 comments on commit 049acb9

Please sign in to comment.