@@ -44,10 +44,15 @@ func SetTokenChanCap(size int) {
44
44
tokChanCap = size
45
45
}
46
46
47
+ // LexScanner provides an interface for scanning tokens.
47
48
type LexScanner interface {
49
+ // Scan is used to advance the scanner to the next token.
48
50
Scan () bool
51
+ // Err returns any error encountered during scanning.
49
52
Err () error
53
+ // Text returns the most recent token generated by Scan as a string.
50
54
Text () string
55
+ // Line returns the line number of the most recent token generated by Scan.
51
56
Line () int
52
57
}
53
58
@@ -164,7 +169,6 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
164
169
la = "\\ " + la
165
170
}
166
171
167
- // special handling for *_by_lua_block directives
168
172
if token .Len () > 0 {
169
173
tokenStr := token .String ()
170
174
if ext , ok := externalLexers [tokenStr ]; ok {
@@ -357,8 +361,8 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
357
361
var inQuotes bool
358
362
359
363
// special handling for'set_by_lua_block' directive
360
- // #nosec G101
361
- if matchedToken == "set_by_lua_block" { //nolint
364
+ // ignore Potential hardcoded credentials linter warning for "set_by_lua_block"
365
+ if matchedToken == "set_by_lua_block" /* #nosec G101 */ {
362
366
arg := ""
363
367
for {
364
368
if ! ll .s .Scan () {
@@ -380,22 +384,23 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
380
384
}
381
385
arg += next
382
386
}
383
- // skip leading whitespace after the return value
384
- for {
385
- if ! ll .s .Scan () {
386
- return
387
- }
388
- next := ll .s .Text ()
387
+ }
389
388
390
- if ! isSpace (next ) {
391
- if next != "{" {
392
- lineno := ll .s .Line ()
393
- tokenCh <- NgxToken {Error : & ParseError {File : & lexerFile , What : `unexpected "}"` , Line : & lineno }}
394
- return
395
- }
396
- tokenDepth ++
397
- break
389
+ // skip leading whitespace after the return value
390
+ for {
391
+ if ! ll .s .Scan () {
392
+ return
393
+ }
394
+ next := ll .s .Text ()
395
+
396
+ if ! isSpace (next ) {
397
+ if next != "{" {
398
+ lineno := ll .s .Line ()
399
+ tokenCh <- NgxToken {Error : & ParseError {File : & lexerFile , What : `expected "{" to start lua block` , Line : & lineno }}
400
+ return
398
401
}
402
+ tokenDepth ++
403
+ break
399
404
}
400
405
}
401
406
0 commit comments