Skip to content

Commit

Permalink
🐛 use window of correct size to grab content from xml files
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Jan 8, 2024
1 parent 320c627 commit 615235c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (b *builtinServiceClient) getLocation(ctx context.Context, path, content st
}()

location.StartPosition.Line = -1
lineNumber, err := provider.MultilineGrep(ctx, len(lines), path, pattern)
lineNumber, err := provider.MultilineGrep(ctx, len(parts), path, pattern)
if err != nil || lineNumber == -1 {
return location, fmt.Errorf("unable to get location in file %s - %w", path, err)
}
Expand Down
8 changes: 8 additions & 0 deletions provider/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func TestMultilineGrep(t *testing.T) {
window: 2,
wantErr: false,
},
{
name: "multi-line complex pattern",
filePath: "./testdata/test.xml",
pattern: ".*?4\\.0\\.0.*?com\\.telran.*?BookServer",
window: 4,
want: 5,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
65 changes: 65 additions & 0 deletions provider/testdata/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.telran</groupId>
<artifactId>BookServer</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.0.RELEASE</version> <!-- 09.11.2018 -->
</plugin>
</plugins>
</build>

<dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.0.RELEASE</version> <!-- 09.11.2018 -->
</dependency>

<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</dependency>

<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.5</version>
</dependency>

<!--&lt;!&ndash; jdbc connector &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>mysql</groupId>-->
<!--<artifactId>mysql-connector-java</artifactId>-->
<!--&lt;!&ndash; <version>8.0.12</version> &ndash;&gt; &lt;!&ndash; TimeZone bug not fixed since 5.1.39 &ndash;&gt;-->
<!--<version>5.1.39</version>-->
<!--</dependency>-->

</dependencies>

</project>

0 comments on commit 615235c

Please sign in to comment.