mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Fix: use l/w match-ing (which does not depend on frames)
this was wrong on LS' end - String#match impl expects a frame (due $~) ... started failing due JRuby reducing frame usage (for blocks) Fixes #11653
This commit is contained in:
parent
7706866fb0
commit
d3d765a455
1 changed files with 17 additions and 11 deletions
|
@ -7,6 +7,7 @@ import java.util.Objects;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
import org.jruby.Ruby;
|
||||
import org.jruby.RubyRegexp;
|
||||
import org.jruby.RubyString;
|
||||
import org.jruby.runtime.builtin.IRubyObject;
|
||||
import org.jruby.util.ByteList;
|
||||
|
@ -467,22 +468,30 @@ public interface EventCondition {
|
|||
!Boolean.toString(false).equals(other);
|
||||
}
|
||||
|
||||
private static RubyRegexp newRegexp(String pattern) {
|
||||
final Ruby runtime = RubyUtil.RUBY;
|
||||
return RubyRegexp.newRegexpFromStr(runtime, runtime.newString(pattern), 0);
|
||||
}
|
||||
|
||||
private static boolean matches(RubyString str, RubyRegexp regexp) {
|
||||
return regexp.match_p(RubyUtil.RUBY.getCurrentContext(), str).isTrue(); // match? returns true/false
|
||||
}
|
||||
|
||||
private static final class FieldMatches implements EventCondition {
|
||||
|
||||
private final FieldReference field;
|
||||
|
||||
private final RubyString regex;
|
||||
private final RubyRegexp regexp;
|
||||
|
||||
private FieldMatches(final String field, final String regex) {
|
||||
private FieldMatches(final String field, final String pattern) {
|
||||
this.field = FieldReference.from(field);
|
||||
this.regex = RubyUtil.RUBY.newString(regex);
|
||||
this.regexp = newRegexp(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fulfilled(final JrubyEventExtLibrary.RubyEvent event) {
|
||||
final Object tomatch = event.getEvent().getUnconvertedField(field);
|
||||
return tomatch instanceof RubyString &&
|
||||
!((RubyString) tomatch).match(RubyUtil.RUBY.getCurrentContext(), regex).isNil();
|
||||
final Object toMatch = event.getEvent().getUnconvertedField(field);
|
||||
return toMatch instanceof RubyString && matches((RubyString) toMatch, regexp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,12 +499,9 @@ public interface EventCondition {
|
|||
|
||||
private final boolean matches;
|
||||
|
||||
private ConstantMatches(final Object constant, final String regex) {
|
||||
final Ruby runtime = RubyUtil.RUBY;
|
||||
private ConstantMatches(final Object constant, final String pattern) {
|
||||
this.matches = constant instanceof String &&
|
||||
!(runtime.newString((String) constant).match(
|
||||
runtime.getCurrentContext(),
|
||||
runtime.newString(regex)).isNil());
|
||||
matches(RubyUtil.RUBY.newString((String) constant), newRegexp(pattern));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue