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