diff --git a/README.md b/README.md index 12a9b05..867c5ca 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Log Reader User Manual 3.3.0 +# Log Reader User Manual 3.3.1 ## Document Information @@ -168,6 +168,12 @@ Output: 8=FIXT.1.1\u00019=66\u000135=A\u000134=1\u000149=NFT2_FIX1\u000156=FGW\u ## Changes +### 3.3.1 + +#### Fixed + ++ Bug when we tried to substitute the values from string extracted from the log if it had content like this `${something}` + ### 3.3.0 + Add support for truncated files. `allowFileTruncate` parameter in `common` configuration is added. diff --git a/gradle.properties b/gradle.properties index c30aed8..124cca7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -release_version=3.3.0 \ No newline at end of file +release_version=3.3.1 \ No newline at end of file diff --git a/src/main/java/com/exactpro/th2/readlog/RegexLogParser.java b/src/main/java/com/exactpro/th2/readlog/RegexLogParser.java index daf6a93..e4ff06d 100644 --- a/src/main/java/com/exactpro/th2/readlog/RegexLogParser.java +++ b/src/main/java/com/exactpro/th2/readlog/RegexLogParser.java @@ -181,14 +181,14 @@ private StringSubstitutor createSubstitutor(Matcher matcher) { Integer index = tryParse(key); if (index == null) { return matcher.group(key); - } else { - if (index < 0) { - throw new IllegalArgumentException("group index cannot be negative"); - } - return matcher.group(index); } + if (index < 0) { + throw new IllegalArgumentException("group index cannot be negative"); + } + return matcher.group(index); }); stringSubstitutor.setEnableUndefinedVariableException(true); // exception if key is unknown + stringSubstitutor.setDisableSubstitutionInValues(true); return stringSubstitutor; } diff --git a/src/test/java/com/exactpro/th2/readlog/TestRegexLogParserJoining.java b/src/test/java/com/exactpro/th2/readlog/TestRegexLogParserJoining.java index 808a0eb..ddac41d 100644 --- a/src/test/java/com/exactpro/th2/readlog/TestRegexLogParserJoining.java +++ b/src/test/java/com/exactpro/th2/readlog/TestRegexLogParserJoining.java @@ -52,6 +52,30 @@ void joinsIfOneMatchFound() { body.get(0)); } + @Test + void doesNotTryToSubstituteInResultString() { + AliasConfiguration configuration = new AliasConfiguration( + "(] )(.*$)", + ".*", + null, + null, + null + ); + configuration.setJoinGroups(true); + configuration.setHeadersFormat(Map.of( + "Header", "Group 2: ${2}" + )); + RegexLogParser parser = new RegexLogParser(Map.of("test", configuration)); + + LogData data = parser.parse(new StreamId("test", Direction.FIRST), "[test] should not try to process ${3} and ${variable}"); + List body = data.getBody(); + Assertions.assertEquals(1, body.size(), () -> "Unexpected strings: " + body); + Assertions.assertEquals( + "\"Header\"\n" + + "\"Group 2: should not try to process ${3} and ${variable}\"", + body.get(0)); + } + @Test void joinsIfManyMatchesFound() { AliasConfiguration configuration = new AliasConfiguration(