koryphe icon indicating copy to clipboard operation
koryphe copied to clipboard

Should the String DeduplicateConcat separator be escaped?

Open m607123 opened this issue 7 years ago • 1 comments

When the input strings are handled, they are split using the .split() method, which uses RegEx - however if the user inputs a character that can be interpreted by RegEx ( pipe symbol, open parentheses etc ) it won't be escaped, and the output will then be incorrect. What would be the best way to handle this - sanitise the inputs, throw an error, or request that the user input a valid delimiter instead?

m607123 avatar Jul 20 '17 14:07 m607123

I think it's a BUG (not a question). Using Pattern to split the separator should require escape the regex special characters such as pipe symbol, etc. I'm using the StringDeduplicateConcat with pipe symbol as separator and it fails to concat. IMHO, it should use StringUtils.split(aString, separator) rather than Pattern without escaping special characters for regex.

Here is my unit test, which is failed

` public void testApplyWithPipeCharacter() {

StringDeduplicateConcat op = new StringDeduplicateConcat();
op.setSeparator("|");
String concatString = op.apply("COMMON_NAME|MY_NAME","COMMON_NAME|YOUR_NAME");
Assert.assertEquals("Should return correct value", "COMMON_NAME|MY_NAME|YOUR_NAME", concatString);

} `

The current code return wrong value: "C|O|M|N|_|A|E||Y|U|R"

xudien avatar Oct 26 '20 15:10 xudien