Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pkg/analysis/topology/string_extraction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package topology_test

import (
"testing"

"github.com/BlackVectorOps/semantic_firewall/v3/pkg/analysis/topology"
"github.com/BlackVectorOps/semantic_firewall/v3/pkg/testutil"
)

// TestStringExtraction verifies that string literals are extracted without quotes.
// This ensures that constant.StringVal is used instead of constant.ExactString.
func TestStringExtraction(t *testing.T) {
t.Parallel()

src := `package main
func stringFunc() {
println("raw_content")
}`

fn := testutil.CompileAndGetFunction(t, src, "stringFunc")
topo := topology.ExtractTopology(fn)

if topo == nil {
t.Fatal("ExtractTopology returned nil")
}

expected := "raw_content"
found := false
for _, lit := range topo.StringLiterals {
if lit == expected {
found = true
}
if lit == `"`+expected+`"` {
t.Errorf("String literal extracted with quotes: %s", lit)
}
}

if !found {
t.Errorf("Expected string literal %q not found. Got: %v", expected, topo.StringLiterals)
}
}
1 change: 0 additions & 1 deletion pkg/analysis/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func ExtractTopology(fn *ssa.Function) *FunctionTopology {
}
if c, ok := (*op).(*ssa.Const); ok && c.Value != nil {
if c.Value.Kind() == constant.String {
// FIX: Use StringVal to get raw string content instead of ExactString which includes quotes
val := constant.StringVal(c.Value)

if len(val) > maxStrLen {
Expand Down
Loading