Skip to content

Commit 65da5a2

Browse files
committed
Restrict filter-path parsing to filter command context
ParsePrimary previously treated any identifier starting with '.' as a FilterPathExpression unconditionally. That broke command arguments like 'jq .msg', where '.msg' is a literal jq program string passed to the external command -- the shell evaluated it against the piped input first. Gate filter-path/filter-call/zero-arg-builtin handling behind an inFilterMode flag set by ParseFilterExpression. The filter command (and Expression.Parse used by tests) enable filter mode; ordinary command arguments keep their previous shell-word semantics.
1 parent 6e000fc commit 65da5a2

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

CosmosDBShell/Azure.Data.Cosmos.Shell.Parser/ExpressionParser.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal class ExpressionParser
1414
private bool initialized = false;
1515
private Token? lastNonNullToken;
1616
private bool aborted = false;
17+
private bool inFilterMode = false;
1718

1819
public ExpressionParser(Lexer lexer)
1920
{
@@ -189,7 +190,16 @@ public Expression ParseFilterExpression()
189190
return this.CreateAbortExpression();
190191
}
191192

192-
return this.ParsePipeExpression();
193+
var previous = this.inFilterMode;
194+
this.inFilterMode = true;
195+
try
196+
{
197+
return this.ParsePipeExpression();
198+
}
199+
finally
200+
{
201+
this.inFilterMode = previous;
202+
}
193203
}
194204

195205
public Expression ParsePrimaryExpression()
@@ -668,7 +678,7 @@ private Expression ParsePrimary()
668678
return new ConstantExpression(token, new ShellJson(FilterExpressionUtilities.NullElement()));
669679
}
670680

671-
if (token.Value.StartsWith(".", StringComparison.Ordinal))
681+
if (this.inFilterMode && token.Value.StartsWith(".", StringComparison.Ordinal))
672682
{
673683
return this.ParseFilterPathExpression(token);
674684
}
@@ -699,12 +709,12 @@ private Expression ParsePrimary()
699709
return new VariableExpression(token, varValue);
700710
}
701711

702-
if (this.Check(TokenType.OpenParenthesis))
712+
if (this.inFilterMode && this.Check(TokenType.OpenParenthesis))
703713
{
704714
return this.ParseFilterCallExpression(token);
705715
}
706716

707-
if (this.IsFilterZeroArgBuiltin(token.Value))
717+
if (this.inFilterMode && this.IsFilterZeroArgBuiltin(token.Value))
708718
{
709719
return new FilterCallExpression(token, []);
710720
}

0 commit comments

Comments
 (0)