Skip to content

Commit

Permalink
chore(scanoss): Throw on unsupported line ranges in convertLines()
Browse files Browse the repository at this point in the history
Do not silently try to coerce to a single int value, but throw
explicitly on an unsupported line range syntax. Also slightly improve the
function documentation by quoting the line range string.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 18, 2024
1 parent 5fff408 commit 97ece6d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions plugins/scanners/scanoss/src/main/kotlin/ScanOssResultParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ private fun getSnippets(details: ScanFileDetails): Set<Snippet> {
}

/**
* Split a [lineRange] returned by ScanOSS such as 1-321 into a [TextLocation] for the given [file].
* Split a [lineRange] returned by ScanOSS such as "1-321" into a [TextLocation] for the given [file].
*/
private fun convertLines(file: String, lineRange: String): TextLocation {
val splitLines = lineRange.split("-")
return if (splitLines.size == 2) {
TextLocation(file, splitLines.first().toInt(), splitLines.last().toInt())
} else {
TextLocation(file, splitLines.first().toInt())

return when (splitLines.size) {
1 -> TextLocation(file, splitLines.first().toInt())
2 -> TextLocation(file, splitLines.first().toInt(), splitLines.last().toInt())
else -> throw IllegalArgumentException("Unsupported line range '$lineRange'.")
}
}

0 comments on commit 97ece6d

Please sign in to comment.