You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/10/25 13:41:04 UTC
[camel] branch main updated: CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows. (#11836)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5143723fb2f CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows. (#11836)
5143723fb2f is described below
commit 5143723fb2f885537942d870e0c603614e22c200
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Oct 25 15:40:57 2023 +0200
CAMEL-20033: camel-jbang - Write to settings properties file using JDK Properties code that escapes key and value so it works on Windows. (#11836)
---
.../org/apache/camel/dsl/jbang/core/commands/Run.java | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 3c718fe5eca..d432e2daec1 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -26,6 +26,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
@@ -1282,10 +1283,22 @@ public class Run extends CamelCommand {
private void writeSettings(String key, String value) {
FileOutputStream fos = null;
try {
+ // use java.util.Properties to ensure the value is escaped correctly
+ Properties prop = new Properties();
+ prop.setProperty(key, value);
+ StringWriter sw = new StringWriter();
+ prop.store(sw, null);
+
fos = new FileOutputStream(WORK_DIR + "/" + RUN_SETTINGS_FILE, true);
- String line = key + "=" + value;
- fos.write(line.getBytes(StandardCharsets.UTF_8));
- fos.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
+
+ String[] lines = sw.toString().split(System.lineSeparator());
+ for (String line : lines) {
+ // properties store timestamp as comment which we want to skip
+ if (!line.startsWith("#")) {
+ fos.write(line.getBytes(StandardCharsets.UTF_8));
+ fos.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
+ }
+ }
} catch (Exception e) {
// ignore
} finally {