From fec81dae7eded0af4f3e6e8432ef43e08371c8b2 Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Tue, 9 Mar 2021 20:27:25 +0800 Subject: [PATCH 1/7] Fix #7416 --- .../java/org/jabref/gui/preferences/PreferencesDialogView.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index e0aae949844..fc47d7a3613 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -52,6 +52,8 @@ public PreferencesDialogView(JabRefFrame frame) { ControlHelper.setAction(saveButton, getDialogPane(), event -> savePreferencesAndCloseDialog()); + this.getDialogPane().setStyle("-fx-font-size: " + preferencesService.getAppearancePreferences().getMainFontSize() + "pt;"); + // ToDo: After conversion of all tabs to mvvm, rework interface and make validSettings bindable // Button btnSave = (Button) this.getDialogPane().lookupButton(saveButton); // btnSave.disableProperty().bind(viewModel.validSettings().validProperty().not()); From 8428b497acb943709a0f3b2c8f8b1b8c65e59534 Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Fri, 12 Mar 2021 09:15:09 +0800 Subject: [PATCH 2/7] sync with origin --- .../java/org/jabref/gui/preferences/PreferencesDialogView.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index fc47d7a3613..e0aae949844 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -52,8 +52,6 @@ public PreferencesDialogView(JabRefFrame frame) { ControlHelper.setAction(saveButton, getDialogPane(), event -> savePreferencesAndCloseDialog()); - this.getDialogPane().setStyle("-fx-font-size: " + preferencesService.getAppearancePreferences().getMainFontSize() + "pt;"); - // ToDo: After conversion of all tabs to mvvm, rework interface and make validSettings bindable // Button btnSave = (Button) this.getDialogPane().lookupButton(saveButton); // btnSave.disableProperty().bind(viewModel.validSettings().validProperty().not()); From 2f8e1516cc74fd5dce836a13f539086367bb5a3b Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Wed, 17 Mar 2021 21:48:39 +0800 Subject: [PATCH 3/7] backtracking file path argument who invoked the method sendMessage(type=SEND_COMMAND_LINE_ARGUMENTS) when double-clicking --- src/main/java/org/jabref/cli/ArgumentProcessor.java | 4 ++++ src/main/java/org/jabref/cli/JabRefCLI.java | 4 ++++ .../java/org/jabref/gui/remote/JabRefMessageHandler.java | 3 +++ .../java/org/jabref/logic/importer/OpenDatabase.java | 1 + .../jabref/logic/remote/server/RemoteListenerServer.java | 3 +++ .../java/org/jabref/logic/remote/shared/Protocol.java | 9 +++++++++ 6 files changed, 24 insertions(+) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index cddb291b07f..fcae89d1d83 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -64,6 +64,9 @@ public class ArgumentProcessor { private boolean noGUINeeded; public ArgumentProcessor(String[] args, Mode startupMode) throws org.apache.commons.cli.ParseException { + for (String s:args) { + LOGGER.info("constructor arg = " + s); + } cli = new JabRefCLI(args); this.startupMode = startupMode; parserResults = processArguments(); @@ -318,6 +321,7 @@ private List importAndOpenFiles() { // Leftover arguments that have a "bib" extension are interpreted as // BIB files to open. Other files, and files that could not be opened // as bib, we try to import instead. + LOGGER.info("aLeftOver = " + aLeftOver); boolean bibExtension = aLeftOver.toLowerCase(Locale.ENGLISH).endsWith("bib"); ParserResult pr = new ParserResult(); if (bibExtension) { diff --git a/src/main/java/org/jabref/cli/JabRefCLI.java b/src/main/java/org/jabref/cli/JabRefCLI.java index e9d26874b00..e22a6470487 100644 --- a/src/main/java/org/jabref/cli/JabRefCLI.java +++ b/src/main/java/org/jabref/cli/JabRefCLI.java @@ -26,6 +26,10 @@ public JabRefCLI(String[] args) throws ParseException { this.cl = new DefaultParser().parse(options, args, true); this.leftOver = cl.getArgList(); + + for (String s:args) { + LOGGER.info("constructor arg = " + s); + } } public static String getExportMatchesSyntax() { diff --git a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java index 10a190a0694..8116b318b0d 100644 --- a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java +++ b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java @@ -18,6 +18,9 @@ public class JabRefMessageHandler implements MessageHandler { @Override public void handleCommandLineArguments(String[] message) { + for (String s:message) { + LOGGER.info("message = " + s); + } try { ArgumentProcessor argumentProcessor = new ArgumentProcessor(message, ArgumentProcessor.Mode.REMOTE_START); diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index 8fec03796a9..9732af4c916 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -61,6 +61,7 @@ public static ParserResult loadDatabase(String name, ImportFormatPreferences imp */ public static ParserResult loadDatabase(Path fileToOpen, ImportFormatPreferences importFormatPreferences, TimestampPreferences timestampPreferences, FileUpdateMonitor fileMonitor) throws IOException { + LOGGER.info("db path: " + fileToOpen.toString()); ParserResult result = new BibtexImporter(importFormatPreferences, fileMonitor).importDatabase(fileToOpen, importFormatPreferences.getEncoding()); diff --git a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java index 901f383a362..1bfa7489987 100644 --- a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java +++ b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java @@ -58,6 +58,9 @@ private void handleMessage(Protocol protocol, RemoteMessage type, Object argumen break; case SEND_COMMAND_LINE_ARGUMENTS: if (argument instanceof String[]) { + for (String s:(String[]) argument) { + LOGGER.info("arg: " + s); + } messageHandler.handleCommandLineArguments((String[]) argument); protocol.sendMessage(RemoteMessage.OK); } else { diff --git a/src/main/java/org/jabref/logic/remote/shared/Protocol.java b/src/main/java/org/jabref/logic/remote/shared/Protocol.java index 27442ab571c..00ec5192754 100644 --- a/src/main/java/org/jabref/logic/remote/shared/Protocol.java +++ b/src/main/java/org/jabref/logic/remote/shared/Protocol.java @@ -4,6 +4,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.Socket; +import java.util.Arrays; import javafx.util.Pair; @@ -38,6 +39,7 @@ public void sendMessage(RemoteMessage type) throws IOException { } public void sendMessage(RemoteMessage type, Object argument) throws IOException { + LOGGER.info("send arg: " + argument.toString()); out.writeObject(type); out.writeObject(argument); out.write('\0'); @@ -50,6 +52,13 @@ public Pair receiveMessage() throws IOException { Object argument = in.readObject(); int endOfMessage = in.read(); + LOGGER.info("recv type: " + type.toString()); + 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') { throw new IOException("Message didn't end on correct end of message identifier. Got " + endOfMessage); } From 5b723bd1f688830bfedb2fa443bc4c64010400d9 Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Thu, 18 Mar 2021 19:44:06 +0800 Subject: [PATCH 4/7] fix #6487 (draft) --- .../jabref/logic/remote/client/RemoteClient.java | 8 +++++++- .../org/jabref/logic/remote/shared/Protocol.java | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java index 6942a902522..190128c36c3 100644 --- a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java +++ b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java @@ -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; @@ -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 response = protocol.receiveMessage(); return response.getKey() == RemoteMessage.OK; } catch (IOException e) { diff --git a/src/main/java/org/jabref/logic/remote/shared/Protocol.java b/src/main/java/org/jabref/logic/remote/shared/Protocol.java index 00ec5192754..a8467b7c11c 100644 --- a/src/main/java/org/jabref/logic/remote/shared/Protocol.java +++ b/src/main/java/org/jabref/logic/remote/shared/Protocol.java @@ -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; @@ -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'); @@ -53,10 +58,16 @@ public Pair 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') { From 9a5811b8529fd50243d69a4278fb9c034263c963 Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Thu, 18 Mar 2021 20:32:48 +0800 Subject: [PATCH 5/7] fix --- CHANGELOG.md | 1 + src/main/java/org/jabref/cli/ArgumentProcessor.java | 4 ---- src/main/java/org/jabref/cli/JabRefCLI.java | 4 ---- .../org/jabref/gui/remote/JabRefMessageHandler.java | 3 --- .../java/org/jabref/logic/importer/OpenDatabase.java | 1 - .../org/jabref/logic/remote/client/RemoteClient.java | 2 ++ .../logic/remote/server/RemoteListenerServer.java | 3 --- .../org/jabref/logic/remote/shared/Protocol.java | 12 ------------ 8 files changed, 3 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cef5ae6bc14..833fe323273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,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 diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index fcae89d1d83..cddb291b07f 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -64,9 +64,6 @@ public class ArgumentProcessor { private boolean noGUINeeded; public ArgumentProcessor(String[] args, Mode startupMode) throws org.apache.commons.cli.ParseException { - for (String s:args) { - LOGGER.info("constructor arg = " + s); - } cli = new JabRefCLI(args); this.startupMode = startupMode; parserResults = processArguments(); @@ -321,7 +318,6 @@ private List importAndOpenFiles() { // Leftover arguments that have a "bib" extension are interpreted as // BIB files to open. Other files, and files that could not be opened // as bib, we try to import instead. - LOGGER.info("aLeftOver = " + aLeftOver); boolean bibExtension = aLeftOver.toLowerCase(Locale.ENGLISH).endsWith("bib"); ParserResult pr = new ParserResult(); if (bibExtension) { diff --git a/src/main/java/org/jabref/cli/JabRefCLI.java b/src/main/java/org/jabref/cli/JabRefCLI.java index e22a6470487..e9d26874b00 100644 --- a/src/main/java/org/jabref/cli/JabRefCLI.java +++ b/src/main/java/org/jabref/cli/JabRefCLI.java @@ -26,10 +26,6 @@ public JabRefCLI(String[] args) throws ParseException { this.cl = new DefaultParser().parse(options, args, true); this.leftOver = cl.getArgList(); - - for (String s:args) { - LOGGER.info("constructor arg = " + s); - } } public static String getExportMatchesSyntax() { diff --git a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java index 8116b318b0d..10a190a0694 100644 --- a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java +++ b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java @@ -18,9 +18,6 @@ public class JabRefMessageHandler implements MessageHandler { @Override public void handleCommandLineArguments(String[] message) { - for (String s:message) { - LOGGER.info("message = " + s); - } try { ArgumentProcessor argumentProcessor = new ArgumentProcessor(message, ArgumentProcessor.Mode.REMOTE_START); diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index 9732af4c916..8fec03796a9 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -61,7 +61,6 @@ public static ParserResult loadDatabase(String name, ImportFormatPreferences imp */ public static ParserResult loadDatabase(Path fileToOpen, ImportFormatPreferences importFormatPreferences, TimestampPreferences timestampPreferences, FileUpdateMonitor fileMonitor) throws IOException { - LOGGER.info("db path: " + fileToOpen.toString()); ParserResult result = new BibtexImporter(importFormatPreferences, fileMonitor).importDatabase(fileToOpen, importFormatPreferences.getEncoding()); diff --git a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java index 190128c36c3..ee563078839 100644 --- a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java +++ b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java @@ -54,10 +54,12 @@ public boolean ping() { */ public boolean sendCommandLineArguments(String[] args) { try (Protocol protocol = openNewConnection()) { + 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 response = protocol.receiveMessage(); return response.getKey() == RemoteMessage.OK; diff --git a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java index 1bfa7489987..901f383a362 100644 --- a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java +++ b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java @@ -58,9 +58,6 @@ private void handleMessage(Protocol protocol, RemoteMessage type, Object argumen break; case SEND_COMMAND_LINE_ARGUMENTS: if (argument instanceof String[]) { - for (String s:(String[]) argument) { - LOGGER.info("arg: " + s); - } messageHandler.handleCommandLineArguments((String[]) argument); protocol.sendMessage(RemoteMessage.OK); } else { diff --git a/src/main/java/org/jabref/logic/remote/shared/Protocol.java b/src/main/java/org/jabref/logic/remote/shared/Protocol.java index a8467b7c11c..9ff988309c4 100644 --- a/src/main/java/org/jabref/logic/remote/shared/Protocol.java +++ b/src/main/java/org/jabref/logic/remote/shared/Protocol.java @@ -6,7 +6,6 @@ import java.net.Socket; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import javafx.util.Pair; @@ -41,10 +40,6 @@ 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'); @@ -57,18 +52,11 @@ public Pair receiveMessage() throws IOException { Object argument = in.readObject(); 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)); - } if (endOfMessage != '\0') { throw new IOException("Message didn't end on correct end of message identifier. Got " + endOfMessage); From fa1885b30ea9e175017cd62a5f3019e6bd524ece Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Fri, 19 Mar 2021 11:15:55 +0800 Subject: [PATCH 6/7] moved encoding to sendMessage created a new test in RemoteCommunicationTest --- .../jabref/logic/remote/client/RemoteClient.java | 10 +--------- .../org/jabref/logic/remote/shared/Protocol.java | 10 ++++++++++ .../logic/remote/RemoteCommunicationTest.java | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java index ee563078839..6942a902522 100644 --- a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java +++ b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java @@ -3,8 +3,6 @@ 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; @@ -54,13 +52,7 @@ public boolean ping() { */ public boolean sendCommandLineArguments(String[] args) { try (Protocol protocol = openNewConnection()) { - - 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); + protocol.sendMessage(RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS, args); Pair response = protocol.receiveMessage(); return response.getKey() == RemoteMessage.OK; } catch (IOException e) { diff --git a/src/main/java/org/jabref/logic/remote/shared/Protocol.java b/src/main/java/org/jabref/logic/remote/shared/Protocol.java index 9ff988309c4..5d83c127ed9 100644 --- a/src/main/java/org/jabref/logic/remote/shared/Protocol.java +++ b/src/main/java/org/jabref/logic/remote/shared/Protocol.java @@ -5,6 +5,7 @@ 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; @@ -40,6 +41,14 @@ public void sendMessage(RemoteMessage type) throws IOException { } public void sendMessage(RemoteMessage type, Object argument) throws IOException { + // encode the commandline arguments to handle special characters (eg. space and Chinese characters) + // related to issue #6487 + if (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS) { + for (int i = 0; i < ((String[]) argument).length; i++) { + ((String[]) argument)[i] = URLEncoder.encode(((String[]) argument)[i], StandardCharsets.UTF_8); + } + } + out.writeObject(type); out.writeObject(argument); out.write('\0'); @@ -52,6 +61,7 @@ public Pair 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); diff --git a/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java b/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java index 9f5a34ed95f..62909102e36 100644 --- a/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java +++ b/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java @@ -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()); verify(server).handleCommandLineArguments(message); } @@ -60,7 +60,7 @@ void commandLineArgumentSinglePassedToServer() { void commandLineArgumentTwoPassedToServer() { final String[] message = new String[]{"my message", "second"}; - client.sendCommandLineArguments(message); + client.sendCommandLineArguments(message.clone()); verify(server).handleCommandLineArguments(message); } @@ -69,7 +69,17 @@ void commandLineArgumentTwoPassedToServer() { void commandLineArgumentMultiLinePassedToServer() { final String[] message = new String[]{"my message\n second line", "second \r and third"}; - client.sendCommandLineArguments(message); + client.sendCommandLineArguments(message.clone()); + + 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.clone()); verify(server).handleCommandLineArguments(message); } From c9182ee139ec8ea876945625708f1bd637e4d971 Mon Sep 17 00:00:00 2001 From: XDZhelheim <601251915@qq.com> Date: Fri, 19 Mar 2021 18:50:54 +0800 Subject: [PATCH 7/7] move clone to sendMessage --- .../org/jabref/logic/remote/shared/Protocol.java | 14 +++++++++----- .../logic/remote/RemoteCommunicationTest.java | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/logic/remote/shared/Protocol.java b/src/main/java/org/jabref/logic/remote/shared/Protocol.java index 5d83c127ed9..6d93122fbe7 100644 --- a/src/main/java/org/jabref/logic/remote/shared/Protocol.java +++ b/src/main/java/org/jabref/logic/remote/shared/Protocol.java @@ -41,16 +41,20 @@ public void sendMessage(RemoteMessage type) throws IOException { } public void sendMessage(RemoteMessage type, Object argument) throws IOException { - // encode the commandline arguments to handle special characters (eg. space and Chinese characters) + out.writeObject(type); + + // encode the commandline arguments to handle special characters (eg. spaces and Chinese characters) // related to issue #6487 if (type == RemoteMessage.SEND_COMMAND_LINE_ARGUMENTS) { - for (int i = 0; i < ((String[]) argument).length; i++) { - ((String[]) argument)[i] = URLEncoder.encode(((String[]) argument)[i], StandardCharsets.UTF_8); + 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.writeObject(type); - out.writeObject(argument); out.write('\0'); out.flush(); } diff --git a/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java b/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java index 62909102e36..02a2b527f6f 100644 --- a/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java +++ b/src/test/java/org/jabref/logic/remote/RemoteCommunicationTest.java @@ -51,7 +51,7 @@ void pingReturnsTrue() throws IOException, InterruptedException { void commandLineArgumentSinglePassedToServer() { final String[] message = new String[]{"my message"}; - client.sendCommandLineArguments(message.clone()); + client.sendCommandLineArguments(message); verify(server).handleCommandLineArguments(message); } @@ -60,7 +60,7 @@ void commandLineArgumentSinglePassedToServer() { void commandLineArgumentTwoPassedToServer() { final String[] message = new String[]{"my message", "second"}; - client.sendCommandLineArguments(message.clone()); + client.sendCommandLineArguments(message); verify(server).handleCommandLineArguments(message); } @@ -69,7 +69,7 @@ void commandLineArgumentTwoPassedToServer() { void commandLineArgumentMultiLinePassedToServer() { final String[] message = new String[]{"my message\n second line", "second \r and third"}; - client.sendCommandLineArguments(message.clone()); + client.sendCommandLineArguments(message); verify(server).handleCommandLineArguments(message); } @@ -79,7 +79,7 @@ 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.clone()); + client.sendCommandLineArguments(message); verify(server).handleCommandLineArguments(message); }