flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apali...@apache.org
Subject flume git commit: FLUME-2753 Error when specifying empty replace string in Search and Replace Interceptor
Date Thu, 06 Aug 2015 20:58:04 GMT
Repository: flume
Updated Branches:
  refs/heads/flume-1.7 c4460bdbf -> 0a34e1e87


FLUME-2753 Error when specifying empty replace string in Search and Replace Interceptor

(Johny Rufus via Ashish Paliwal)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/0a34e1e8
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/0a34e1e8
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/0a34e1e8

Branch: refs/heads/flume-1.7
Commit: 0a34e1e87d10b281fb37971421c651e0847a27f1
Parents: c4460bd
Author: Ashish <apaliwal@apache.org>
Authored: Thu Aug 6 13:55:43 2015 -0700
Committer: Ashish <apaliwal@apache.org>
Committed: Thu Aug 6 13:57:09 2015 -0700

----------------------------------------------------------------------
 .../flume/interceptor/SearchAndReplaceInterceptor.java   |  8 +++++---
 .../interceptor/TestSearchAndReplaceInterceptor.java     | 11 +++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/0a34e1e8/flume-ng-core/src/main/java/org/apache/flume/interceptor/SearchAndReplaceInterceptor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/interceptor/SearchAndReplaceInterceptor.java
b/flume-ng-core/src/main/java/org/apache/flume/interceptor/SearchAndReplaceInterceptor.java
index 6f5c146..b8588cd 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/interceptor/SearchAndReplaceInterceptor.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/interceptor/SearchAndReplaceInterceptor.java
@@ -105,9 +105,11 @@ public class SearchAndReplaceInterceptor implements Interceptor {
           " (may not be empty)");
 
       replaceString = context.getString(REPLACE_STRING_KEY);
-      Preconditions.checkNotNull(replaceString,
-          "Must supply a replacement string " + REPLACE_STRING_KEY +
-          " (empty is ok)");
+      // Empty replacement String value or if the property itself is not present
+      // assign empty string as replacement
+      if(replaceString == null) {
+        replaceString = "";
+      }
 
       searchRegex = Pattern.compile(searchPattern);
 

http://git-wip-us.apache.org/repos/asf/flume/blob/0a34e1e8/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
index b39f912..2ab15f5 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
@@ -84,4 +84,15 @@ public class TestSearchAndReplaceInterceptor {
     context.put("replaceString", "REDACTED");
     testSearchReplace(context, input, output);
   }
+
+  @Test
+  public void testReplaceEmpty() throws Exception {
+    final String input = "Abc123@test.com";
+    final String output = "@test.com";
+    Context context = new Context();
+    context.put("searchPattern", "^[A-Za-z0-9_]+");
+    testSearchReplace(context, input, output);
+    context.put("replaceString", "");
+    testSearchReplace(context, input, output);
+  }
 }
\ No newline at end of file


Mime
View raw message