diff --git a/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go b/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go index 67592a94adc..0f77f4e46df 100644 --- a/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go +++ b/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go @@ -86,6 +86,25 @@ func switchStatementReturningNilOnlyWhenConstant(s string) *string { return &str } +func multipleSwitchStatementReturningTrueOnlyWhenConstant(s string, t string) bool { + switch s { + case constantGlobalVariable, "string literal": + return true + case getRandomString(): + return false + } + switch s { + case "another string literal": + return true + } + switch t { + case "another string literal": + return false + default: + return false + } +} + func switchStatementWithoutUsefulInfo(s string) bool { switch s { case constantGlobalVariable, "string literal": @@ -149,6 +168,15 @@ func main() { } } + { + s := source() + if multipleSwitchStatementReturningTrueOnlyWhenConstant(s, getRandomString()) { + sink(s) + } else { + sink(s) // $dataflow=s + } + } + { s := source() if switchStatementWithoutUsefulInfo(s) {