Skip to content

Commit 88f6c10

Browse files
Copilotharp-intel
andcommitted
Fix extractPCIIDFromBrackets to handle edge cases
- Search for closing bracket after opening bracket - Correctly calculate slice indices to avoid errors - Handle edge cases like backwards brackets and multiple brackets Co-authored-by: harp-intel <[email protected]>
1 parent e006713 commit 88f6c10

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/report/table_helpers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,9 @@ type GPU struct {
14931493
// Example: "Product Name [1414:5353]" returns "1414:5353"
14941494
func extractPCIIDFromBrackets(text string) string {
14951495
if idx := strings.Index(text, "["); idx != -1 {
1496-
if endIdx := strings.Index(text, "]"); endIdx != -1 {
1497-
ids := text[idx+1 : endIdx]
1496+
// Search for closing bracket after the opening bracket
1497+
if endIdx := strings.Index(text[idx+1:], "]"); endIdx != -1 {
1498+
ids := text[idx+1 : idx+1+endIdx]
14981499
if strings.Contains(ids, ":") {
14991500
return ids
15001501
}

0 commit comments

Comments
 (0)