MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseUnset

Function parseUnset

source code/utils/bash/bashParser.ts:3652–3688  ·  view source on GitHub ↗
(P: ParseState, kwTok: Token)

Source from the content-addressed store, hash-verified

3650}
3651
3652function parseUnset(P: ParseState, kwTok: Token): TsNode {
3653 const kw = leaf(P, 'unset', kwTok)
3654 const kids: TsNode[] = [kw]
3655 while (true) {
3656 skipBlanks(P.L)
3657 const c = peek(P.L)
3658 if (
3659 c === '' ||
3660 c === '\n' ||
3661 c === ';' ||
3662 c === '&' ||
3663 c === '|' ||
3664 c === ')' ||
3665 c === '<' ||
3666 c === '>'
3667 ) {
3668 break
3669 }
3670 // SECURITY: use parseWord (not raw nextToken) so quoted strings like
3671 // `unset 'a[$(id)]'` emit a raw_string child that ast.ts can reject.
3672 // Previously `break` silently dropped non-WORD args — hiding the
3673 // arithmetic-subscript code-exec vector from the security walker.
3674 const arg = parseWord(P, 'arg')
3675 if (!arg) break
3676 if (arg.type === 'word') {
3677 if (arg.text.startsWith('-')) {
3678 kids.push(arg)
3679 } else {
3680 kids.push(mk(P, 'variable_name', arg.startIndex, arg.endIndex, []))
3681 }
3682 } else {
3683 kids.push(arg)
3684 }
3685 }
3686 const last = kids[kids.length - 1]!
3687 return mk(P, 'unset_command', kw.startIndex, last.endIndex, kids)
3688}
3689
3690function consumeKeyword(P: ParseState, name: string, kids: TsNode[]): void {
3691 skipNewlines(P)

Callers 1

parseCommandFunction · 0.85

Calls 5

leafFunction · 0.85
skipBlanksFunction · 0.85
parseWordFunction · 0.85
mkFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected