Sha256: 078ee6af6306d6fb533ff2dae76d3a379758275ec14f64dd29d265ad0922a4b1

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

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

#include "cs__assess_array.h"
#include "../cs__common/cs__common.h"
#include <ruby.h>

/*
 * If String#split is called without an argument, it defaults to use `$;`.
 * We have to make this patch in C so as not to change that value.
 * -HM
 */
static VALUE contrast_assess_array_join(const int argc, const VALUE *argv,
                                        const VALUE ary) {
    VALUE sep, result;
    /* We need to figure out the separator the join method actually used. */
    /* First, check if one was provided. */
    rb_scan_args(argc, argv, "01", &sep);
    /* Second, check to see if `$;` is set*/
    if (NIL_P(sep)) {
        sep = rb_output_fs;
    }
    /* Finally, default to empty String. Implicit since nil.to_s is ''*/

    result = rb_funcall2(ary, rb_sym_assess_array_join, argc, argv);
    result = rb_funcall(array_propagator, rb_sym_assess_track_array_join, 3, ary, sep, result);

    return result;
}

void Init_cs__assess_array(void) {
    array_propagator = rb_define_class_under(core_assess, "ArrayPropagator", rb_cObject);
    rb_sym_assess_track_array_join = rb_intern("cs__track_join");
    rb_sym_assess_array_join = contrast_register_patch("Array",
                                                       "join",
                                                       contrast_assess_array_join);
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-3.13.2 ext/cs__assess_array/cs__assess_array.c
contrast-agent-3.13.1 ext/cs__assess_array/cs__assess_array.c
contrast-agent-3.13.0 ext/cs__assess_array/cs__assess_array.c
contrast-agent-3.12.2 ext/cs__assess_array/cs__assess_array.c
contrast-agent-3.12.1 ext/cs__assess_array/cs__assess_array.c
contrast-agent-3.12.0 ext/cs__assess_array/cs__assess_array.c