/* Copyright (c) 2020 Contrast Security, Inc. See * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */ #include "cs__assess_regexp.h" #include void contrast_alias_method(const VALUE target, const char *to, const char *from); static VALUE contrast_assess_regexp_equal_squiggle(const int argc, const VALUE *argv, const VALUE regexp) { VALUE result, infohash; result = rb_funcall2(regexp, rb_sym_assess_regexp_equal_squiggle, argc, argv); if (RTEST(result)) { infohash = rb_hash_new(); rb_hash_aset(infohash, rb_sym_regexp, regexp); rb_hash_aset(infohash, rb_sym_result, result); rb_hash_aset(infohash, rb_sym_string, argv[0]); rb_hash_aset(infohash, rb_sym_back_ref, rb_backref_get()); rb_funcall(regexp, rb_sym_assess_track_regexp, 1, infohash); } return result; } void Init_cs__assess_regexp(void) { rb_sym_assess_regexp_equal_squiggle = rb_intern("cs__patched_equal_squiggle"); rb_sym_assess_track_regexp = rb_intern("cs__regexp_tagger"); rb_sym_result = ID2SYM(rb_intern("result")); rb_global_variable(&rb_sym_result); rb_sym_regexp = ID2SYM(rb_intern("regexp")); rb_global_variable(&rb_sym_regexp); rb_sym_string = ID2SYM(rb_intern("string")); rb_global_variable(&rb_sym_string); rb_sym_back_ref = ID2SYM(rb_intern("back_ref")); rb_global_variable(&rb_sym_back_ref); VALUE regexp_class = rb_define_class("Regexp", rb_cObject); contrast_alias_method(regexp_class, "cs__patched_equal_squiggle", "=~"); rb_define_method(regexp_class, "=~", contrast_assess_regexp_equal_squiggle, -1); }