Skip to content

Commit 2c4a570

Browse files
authored
Merge pull request #133 from github/ci/pr-129
Replicate work in PR #129 - fix panic in parseWith
2 parents 148e586 + 2289847 commit 2c4a570

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

spdxexp/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (t *tokenStream) parseWith() *string {
380380
}
381381

382382
token := t.peek()
383-
if token.role != exceptionToken {
383+
if token == nil || token.role != exceptionToken {
384384
t.err = errors.New("expected exception after 'WITH'")
385385
return nil
386386
}

spdxexp/parse_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ func TestParseWith(t *testing.T) {
12461246
{"WITH followed by EXCEPTION", getWithClauseTokens(1), "Bison-exception-2.2", false, 2, nil},
12471247
{"WITH not followed by EXCEPTION", getInvalidWithClauseTokens(1), "", true, 2, errors.New("expected exception after 'WITH'")},
12481248
{"not with", getOrClauseTokens(1), "", true, 1, nil},
1249+
{"WITH not followed by any tokens", getMalformedWithClauseTokens(1), "", true, 2, errors.New("expected exception after 'WITH'")},
12491250
}
12501251

12511252
for _, test := range tests {
@@ -1292,6 +1293,13 @@ func getInvalidWithClauseTokens(index int) *tokenStream {
12921293
return getTokenStream(tokens, index)
12931294
}
12941295

1296+
func getMalformedWithClauseTokens(index int) *tokenStream {
1297+
var tokens []token
1298+
tokens = append(tokens, token{role: licenseToken, value: "Apache-2.0"})
1299+
tokens = append(tokens, token{role: operatorToken, value: "WITH"})
1300+
return getTokenStream(tokens, index)
1301+
}
1302+
12951303
func getAndClauseTokens(index int) *tokenStream {
12961304
var tokens []token
12971305
tokens = append(tokens, token{role: licenseToken, value: "MIT"})

0 commit comments

Comments
 (0)