Skip to content

Commit

Permalink
fix: Fix Svace defects and update unit tests (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov authored Apr 10, 2024
1 parent 15140e7 commit 53193bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<configuration>
<excludes>**/*$*</excludes>
</configuration>
<executions>
<execution>
<goals>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/lpvs/entity/LPVSFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.util.Set;

/**
Expand Down Expand Up @@ -153,7 +154,9 @@ public String convertLicensesToString(LPVSVcs vcs) {
*/
public String convertBytesToLinesNumbers() {

if (matchedLines != null && !matchedLines.startsWith("BYTES:")) {
if (matchedLines == null || matchedLines.isEmpty()) {
return "";
} else if (matchedLines != null && !matchedLines.startsWith("BYTES:")) {
return matchedLines;
}

Expand Down Expand Up @@ -183,7 +186,7 @@ public String convertBytesToLinesNumbers() {
if (startLine > 0 && endLine == 0) endLine = currentLine;
break;
}
byteCounter += line.getBytes().length + 1;
byteCounter += line.getBytes(StandardCharsets.UTF_8).length + 1;
if (byteCounter > startByte && startLine == 0) {
startLine = currentLine;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/lpvs/entity/LPVSFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,14 @@ public void testConvertBytesToLinesNumbers_N() throws URISyntaxException {
invalidFile.setMatchedLines("BYTES:0-3709:6492-7819");
String result = invalidFile.convertBytesToLinesNumbers();
assertEquals("", result);

// Empty matched lines
invalidFile.setMatchedLines(null);
result = invalidFile.convertBytesToLinesNumbers();
assertEquals("", result);

invalidFile.setMatchedLines("");
result = invalidFile.convertBytesToLinesNumbers();
assertEquals("", result);
}
}

0 comments on commit 53193bf

Please sign in to comment.