You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ro...@apache.org on 2018/10/12 17:05:21 UTC
svn commit: r1843692 - in /pig/trunk: CHANGES.txt
src/org/apache/pig/tools/parameters/PreprocessorContext.java
test/org/apache/pig/tools/parameters/TestPreprocessorContext.java
Author: rohini
Date: Fri Oct 12 17:05:21 2018
New Revision: 1843692
URL: http://svn.apache.org/viewvc?rev=1843692&view=rev
Log:
PIG-5362: Parameter substitution of shell cmd results doesn't handle backslash (wlauer via rohini)
Modified:
pig/trunk/CHANGES.txt
pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java
pig/trunk/test/org/apache/pig/tools/parameters/TestPreprocessorContext.java
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1843692&r1=1843691&r2=1843692&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Fri Oct 12 17:05:21 2018
@@ -88,6 +88,8 @@ OPTIMIZATIONS
BUG FIXES
+PIG-5362: Parameter substitution of shell cmd results doesn't handle backslash (wlauer via rohini)
+
PIG-5355: Negative progress report by HBaseTableRecordReader (satishsaley via knoguchi)
PIG-5341: PigStorage with -tagFile/-tagPath produces incorrect results with column pruning (knoguchi)
Modified: pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java?rev=1843692&r1=1843691&r2=1843692&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java (original)
+++ pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java Fri Oct 12 17:05:21 2018
@@ -352,9 +352,7 @@ public class PreprocessorContext {
throw new ParameterSubstitutionException(message);
}
val = paramval_get(key);
- if (val.contains("$")) {
- val = val.replaceAll("(?<!\\\\)\\$", "\\\\\\$");
- }
+ val = Matcher.quoteReplacement(val);
replaced_line = replaced_line.replaceFirst("\\$\\{"+key+"\\}", val);
}
}
@@ -379,9 +377,7 @@ public class PreprocessorContext {
throw new ParameterSubstitutionException(message);
}
val = paramval_get(key);
- if (val.contains("$")) {
- val = val.replaceAll("(?<!\\\\)\\$", "\\\\\\$");
- }
+ val = Matcher.quoteReplacement(val);
replaced_line = replaced_line.replaceFirst("\\$"+key, val);
}
}
Modified: pig/trunk/test/org/apache/pig/tools/parameters/TestPreprocessorContext.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/tools/parameters/TestPreprocessorContext.java?rev=1843692&r1=1843691&r2=1843692&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/tools/parameters/TestPreprocessorContext.java (original)
+++ pig/trunk/test/org/apache/pig/tools/parameters/TestPreprocessorContext.java Fri Oct 12 17:05:21 2018
@@ -66,4 +66,15 @@ public class TestPreprocessorContext {
);
}
}
+
+ @Test
+ public void testEscaping() throws ParameterSubstitutionException, FrontendException {
+ PreprocessorContext ctx = new PreprocessorContext(0);
+ // quote argument to echo so that the shell doesn't treat the backslash as an escape and consume it
+ String cmd = "echo '$\\stuff'";
+ ctx.processShellCmd("some_value", "`" + cmd + "`");
+
+ String subVal = ctx.substitute("$some_value");
+ assertEquals("$\\stuff", subVal);
+ }
}