Sha256: 2035457d0741277ce2643aec0b817ba09130d55cdca09cdb2ed879a0395128b6

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 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(ary, rb_sym_assess_track_array_join, 2, sep, result);

    return result;
}

void Init_cs__assess_array(void) {
    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

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-3.11.0 ext/cs__assess_array/cs__assess_array.c