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

Function walkTestExpr

source code/utils/bash/ast.ts:964–1011  ·  view source on GitHub ↗

* Recursively walk a test_command expression tree (unary/binary/negated/ * parenthesized expressions). Leaves are test_operator tokens and operands * (word/string/number/etc). Operands are validated via walkArgument.

(
  node: Node,
  argv: string[],
  innerCommands: SimpleCommand[],
  varScope: Map<string, string>,
)

Source from the content-addressed store, hash-verified

962 * (word/string/number/etc). Operands are validated via walkArgument.
963 */
964function walkTestExpr(
965 node: Node,
966 argv: string[],
967 innerCommands: SimpleCommand[],
968 varScope: Map<string, string>,
969): ParseForSecurityResult | null {
970 switch (node.type) {
971 case 'unary_expression':
972 case 'binary_expression':
973 case 'negated_expression':
974 case 'parenthesized_expression': {
975 for (const c of node.children) {
976 if (!c) continue
977 const err = walkTestExpr(c, argv, innerCommands, varScope)
978 if (err) return err
979 }
980 return null
981 }
982 case 'test_operator':
983 case '!':
984 case '(':
985 case ')':
986 case '&&':
987 case '||':
988 case '==':
989 case '=':
990 case '!=':
991 case '<':
992 case '>':
993 case '=~':
994 argv.push(node.text)
995 return null
996 case 'regex':
997 case 'extglob_pattern':
998 // RHS of =~ or ==/!= in [[ ]]. Pattern text only — no code execution.
999 // Parser emits these as leaf nodes with no children (any $(...) or ${...}
1000 // inside the pattern is a sibling, not a child, and is walked separately).
1001 argv.push(node.text)
1002 return null
1003 default: {
1004 // Operand — word, string, number, etc. Validate via walkArgument.
1005 const arg = walkArgument(node, innerCommands, varScope)
1006 if (typeof arg !== 'string') return arg
1007 argv.push(arg)
1008 return null
1009 }
1010 }
1011}
1012
1013/**
1014 * A `redirected_statement` wraps a command (or pipeline) plus one or more

Callers 1

collectCommandsFunction · 0.85

Calls 1

walkArgumentFunction · 0.85

Tested by

no test coverage detected