Skip to content

Commit

Permalink
Merge pull request #26 from th2-net/th2-2843
Browse files Browse the repository at this point in the history
[Th2-2843] Correct problem with variable substitution from extracted …
  • Loading branch information
OptimumCode authored Dec 10, 2021
2 parents 5d45f6f + 84e584d commit 9ce5982
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Log Reader User Manual 3.3.0
# Log Reader User Manual 3.3.1

## Document Information

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version=3.3.0
release_version=3.3.1
10 changes: 5 additions & 5 deletions src/main/java/com/exactpro/th2/readlog/RegexLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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(
Expand Down

0 comments on commit 9ce5982

Please sign in to comment.