You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by sh...@apache.org on 2020/05/12 04:50:14 UTC

[samza] branch master updated: SAMZA-2523: Update Util#envVarEscape to escape more characters (#1359)

This is an automated email from the ASF dual-hosted git repository.

shanthoosh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza.git


The following commit(s) were added to refs/heads/master by this push:
     new ca57730  SAMZA-2523: Update Util#envVarEscape to escape more characters (#1359)
ca57730 is described below

commit ca57730d53324730540039adbad38157b842c88c
Author: Ke Wu <ke...@icloud.com>
AuthorDate: Mon May 11 21:50:03 2020 -0700

    SAMZA-2523: Update Util#envVarEscape to escape more characters (#1359)
    
    Symptom: Job to fail to launch.
    Cause: Backslash and grave accent in submission config is not properly escaped, causing launch.sh to break.
    Changes: Update Util#envVarEscape to escape backslash as well as grave accent.
    Tests: Unit tests updated to test such cases.
    API Changes: None
    Upgrade Instructions: None
    Usage Instructions: None
    
    Co-authored-by: Ke Wu <kw...@linkedin.com>
---
 samza-core/src/main/java/org/apache/samza/util/Util.java     | 6 +++++-
 samza-core/src/test/java/org/apache/samza/util/TestUtil.java | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/samza-core/src/main/java/org/apache/samza/util/Util.java b/samza-core/src/main/java/org/apache/samza/util/Util.java
index 875b6da..4b97014 100644
--- a/samza-core/src/main/java/org/apache/samza/util/Util.java
+++ b/samza-core/src/main/java/org/apache/samza/util/Util.java
@@ -45,7 +45,11 @@ public class Util {
    * Make an environment variable string safe to pass.
    */
   public static String envVarEscape(String str) {
-    return str.replace("\"", "\\\"").replace("'", "\\'");
+    return str
+        .replace("\\", "\\\\")
+        .replace("\"", "\\\"")
+        .replace("'", "\\'")
+        .replace("`", "\\`");
   }
 
   public static String getSamzaVersion() {
diff --git a/samza-core/src/test/java/org/apache/samza/util/TestUtil.java b/samza-core/src/test/java/org/apache/samza/util/TestUtil.java
index 2eb2e89..fe38991 100644
--- a/samza-core/src/test/java/org/apache/samza/util/TestUtil.java
+++ b/samza-core/src/test/java/org/apache/samza/util/TestUtil.java
@@ -50,8 +50,8 @@ public class TestUtil {
     String noSpecialCharacters = "hello world 123 .?!";
     assertEquals(noSpecialCharacters, Util.envVarEscape(noSpecialCharacters));
 
-    String withSpecialCharacters = "quotation \" apostrophe '";
-    String escaped = "quotation \\\" apostrophe \\'";
+    String withSpecialCharacters = "quotation \" apostrophe ' backslash \\ grave accent `";
+    String escaped = "quotation \\\" apostrophe \\' backslash \\\\ grave accent \\`";
     assertEquals(escaped, Util.envVarEscape(withSpecialCharacters));
   }