Copilot commented on code in PR #12871:
URL: https://github.com/apache/trafficserver/pull/12871#discussion_r2785059040
##########
tools/hrw4u/src/visitor.py:
##########
@@ -480,7 +480,13 @@ def visitComparison(self, ctx, *, last: bool = False) ->
None:
if not lhs:
return
operator = ctx.getChild(1)
- negate = operator.symbol.type in (hrw4uParser.NEQ,
hrw4uParser.NOT_TILDE)
+
+ # Detect negation: '!=' and '!~' are single tokens (NEQ,
NOT_TILDE),
+ # but '!in' is two separate tokens ('!' + IN).
+ if operator.getText() == '!':
+ negate = True
+ else:
+ negate = operator.symbol.type in (hrw4uParser.NEQ,
hrw4uParser.NOT_TILDE)
Review Comment:
Negation handling here doesn’t account for an already-active unary `!` from
`emit_factor()`. `_make_condition()` effectively ORs `self._cond_state.not_`
with `negate`, so expressions like `!(a != b)`, `!(a !~ /re/)`, or `!(a !in
[...])` will incorrectly remain negated instead of canceling out
(double-negation should invert back to the positive form). Consider computing
an overall negation via XOR (e.g., `overall_negate = self._cond_state.not_ ^
operator_negate`), clearing `self._cond_state.not_` before calling
`_make_condition()`, and adding a regression test for `!(... != ...)` / `!(...
!in ...)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]