Sha256: 6b6aeb0b3826d07c50b890cf4760fbb51db0b4d7a817068e9f37fd92d3814156

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

/* Copyright (c) 2020 Contrast Security, Inc.  See
 * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */

#include "cs__assess_regexp.h"
#include <ruby.h>

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);
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.10.1 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.10.0 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.9.1 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.9.0 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.8.5 ext/cs__assess_regexp/cs__assess_regexp.c
contrast-agent-3.8.4 ext/cs__assess_regexp/cs__assess_regexp.c