mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Evaluate char literals in pipeline rules (#24295)
* evaluate char literals in pipeline rules * CL --------- Co-authored-by: Maxwell <98284293+kodjo-anipah@users.noreply.github.com>
This commit is contained in:
5
changelog/unreleased/issue-24247.toml
Normal file
5
changelog/unreleased/issue-24247.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
type = "f"
|
||||
message = "Honor character literals in pipeline rules."
|
||||
|
||||
pulls = ["24295"]
|
||||
issues = ["24247"]
|
||||
@@ -511,10 +511,18 @@ public class PipelineRuleParser {
|
||||
exprs.put(ctx, expr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle chars like strings.
|
||||
* There is no dedicated char type for Graylog rules and, strictly speaking, we should error out. But we have
|
||||
* been silently allowing (and ignoring) chars for 10 years.To not break existing rules, we continue to allow
|
||||
* them. Except now we actually honor the expression value.
|
||||
*/
|
||||
@Override
|
||||
public void exitChar(RuleLangParser.CharContext ctx) {
|
||||
// TODO
|
||||
super.exitChar(ctx);
|
||||
final String text = unescape(unquote(ctx.getText(), '\''));
|
||||
final StringExpression expr = new StringExpression(ctx.getStart(), text);
|
||||
log.trace("CHAR: ctx {} => {}", ctx, expr);
|
||||
exprs.put(ctx, expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -266,6 +266,16 @@ class PipelineRuleParserTest extends BaseParserTest {
|
||||
assertTrue(actionsTriggered.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void charLiteral() {
|
||||
final Rule rule = parseRuleWithOptionalCodegen();
|
||||
Message message = messageFactory.createMessage("hello test", "source", DateTime.now(DateTimeZone.UTC));
|
||||
final Message processedMsg = evaluateRule(rule, message);
|
||||
|
||||
assertNotNull(processedMsg);
|
||||
assertEquals("x", processedMsg.getField("x"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void typedFieldAccess() throws Exception {
|
||||
final Rule rule = parseRuleWithOptionalCodegen();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
rule "char_literal"
|
||||
when
|
||||
true
|
||||
then
|
||||
set_field(field: "x", value: 'x');
|
||||
end
|
||||
Reference in New Issue
Block a user