Skip to content

Commit

Permalink
fix JabRef#6487 (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
XDZhelheim committed Mar 18, 2021
1 parent 2f8e151 commit 5b723bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import javafx.util.Pair;

Expand Down Expand Up @@ -52,7 +54,11 @@ public boolean ping() {
*/
public boolean sendCommandLineArguments(String[] args) {
try (Protocol protocol = openNewConnection()) {
protocol.sendMessage(RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS, args);
String[] encodedArgs = args.clone();
for (int i = 0; i < encodedArgs.length; i++) {
encodedArgs[i] = URLEncoder.encode(encodedArgs[i], StandardCharsets.UTF_8);
}
protocol.sendMessage(RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS, encodedArgs);
Pair<RemoteMessage, Object> response = protocol.receiveMessage();
return response.getKey() == RemoteMessage.OK;
} catch (IOException e) {
Expand Down
15 changes: 13 additions & 2 deletions 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,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import javafx.util.Pair;
Expand Down Expand Up @@ -40,6 +42,9 @@ public void sendMessage(RemoteMessage type) throws IOException {

public void sendMessage(RemoteMessage type, Object argument) throws IOException {
LOGGER.info("send arg: " + argument.toString());
// if (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS && argument instanceof String) {
// argument = URLEncoder.encode((String) argument, StandardCharsets.UTF_8);
// }
out.writeObject(type);
out.writeObject(argument);
out.write('\0');
Expand All @@ -53,10 +58,16 @@ public Pair<RemoteMessage, Object> receiveMessage() throws IOException {
int endOfMessage = in.read();

LOGGER.info("recv type: " + type.toString());
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 (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS && argument instanceof String) {
// argument = URLDecoder.decode((String) argument, StandardCharsets.UTF_8);
// }
if (argument instanceof String[]) {
LOGGER.info(Arrays.toString((String[]) argument));
// argument = StringUtil.join((String[]) argument, " ", 0, ((String[]) argument).length);
// argument = new String[]{(String) argument};
}

if (endOfMessage != '\0') {
Expand Down

0 comments on commit 5b723bd

Please sign in to comment.