Module: Ibex::Runtime::EventSanitizer
- Defined in:
- lib/json5/generated_parser.rb
Overview
Converts application-owned values into bounded, data-only event summaries. rubocop:disable Metrics/ModuleLength
Constant Summary collapse
- MAX_DEPTH =
3- MAX_COLLECTION_ENTRIES =
16- MAX_STRING_BYTES =
256- MAX_INTEGER_BITS =
64- STRING_INPUT_BYTES =
1_024- DATA_MAX_DEPTH =
16
Class Method Summary collapse
- .class_name(input) ⇒ Object
-
.data(input) ⇒ Object
Copy a runtime payload into deeply frozen JSON data.
- .location(location) ⇒ Object
- .string(input) ⇒ Object
- .value(input) ⇒ Object
Class Method Details
.class_name(input) ⇒ Object
3733 3734 3735 3736 3737 3738 3739 |
# File 'lib/json5/generated_parser.rb', line 3733 def class_name(input) klass = core_call(Object, :class, input) name = core_call(Module, :name, klass) core_type?(name, String) && !core_call(String, :empty?, name) ? string(name) : "<anonymous>" rescue StandardError "<unknown>" end |
.data(input) ⇒ Object
Copy a runtime payload into deeply frozen JSON data. Unknown objects are summarized instead of being retained, so callers cannot smuggle mutable application identities into an Event.
3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 |
# File 'lib/json5/generated_parser.rb', line 3672 def data(input) result = {} # @type var result: Hash[String, json_value] consumed = 0 core_call(Hash, :each_pair, input) do |key, raw| break if consumed == MAX_COLLECTION_ENTRIES consumed += 1 result[data_key(key)] = json_data(raw, depth: 0, seen: {}) end result.freeze rescue StandardError { "unavailable" => "event_data" }.freeze end |
.location(location) ⇒ Object
3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 |
# File 'lib/json5/generated_parser.rb', line 3694 def location(location) return nil unless location fields = { "file" => location_field(location, :file), "line" => location_field(location, :line), "column" => location_field(location, :column), "end_line" => location_field(location, :end_line), "end_column" => location_field(location, :end_column) } fields.compact.transform_values { |entry| value(entry) }.freeze rescue StandardError unavailable("location") end |
.string(input) ⇒ Object
3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 |
# File 'lib/json5/generated_parser.rb', line 3710 def string(input) return "<unavailable>" unless core_type?(input, String) prefix = core_call(String, :byteslice, input, 0, STRING_INPUT_BYTES) || "" encoded = core_call( String, :encode, prefix, Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "\uFFFD" ) encoded_bytes = core_call(String, :bytesize, encoded) input_bytes = core_call(String, :bytesize, input) return encoded.freeze if encoded_bytes <= MAX_STRING_BYTES && input_bytes <= STRING_INPUT_BYTES truncate_utf8(encoded) rescue StandardError "<unavailable>" end |
.value(input) ⇒ Object
3687 3688 3689 3690 3691 |
# File 'lib/json5/generated_parser.rb', line 3687 def value(input) summarize(input, depth: 0, seen: {}) rescue StandardError unavailable("sanitization") end |