Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid FieldReferences still occur when [,] are embedded in field names #14777

Closed
robbavey opened this issue Nov 23, 2022 · 1 comment
Closed

Comments

@robbavey
Copy link
Member

#14044 was introduced to fix a long-standing issue where setting a field whose name includes characters that are reserved in the FieldReference syntax ([ and ]) had undefined behaviour that resulted in pipeline crashes or the silent truncation of the field name. However, this does not work when these characters are in the middle of the fieldname, rather than at the beginning:

A simple test:

    context 'with map value whose keys have embedded FieldReference-special characters' do
      let(:event) { LogStash::Event.new }
      let(:value) { {"this[field]" => "okay"} }
      it 'sets the value correctly' do
        event.set('this[mixed]field', value.dup)
        expect(event.get('this[mixed]field')).to eq(value)
      end
    end

Results in the following:

  1) LogStash::Event#set with map value whose keys have embedded FieldReference-special characters sets the value correctly
         Failure/Error: event.set('this[mixed]field', value.dup)
         
         RuntimeError:
           Invalid FieldReference: `this[mixed]field`
         # ./logstash-core/spec/logstash/event_spec.rb:209:in `block in <main>'
         # ./spec/spec_helper.rb:66:in `block in <main>'
         # ./logstash-core/lib/logstash/util.rb:43:in `set_thread_name'
         # ./spec/spec_helper.rb:65:in `block in <main>'
         # ./spec/spec_helper.rb:58:in `block in <main>'
         # ./vendor/bundle/jruby/2.6.0/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block in <main>'
         # ./vendor/bundle/jruby/2.6.0/gems/logstash-devutils-2.4.0-java/lib/logstash/devutils/rspec/spec_helper.rb:61:in `block in <main>'
         # ./lib/bootstrap/rspec.rb:36:in `<main>'

Note that using the event constructor instead of the set method does not result in the same error:

    it 'accepts maps whose keys contain embedded FieldReference-special characters' do
      e = LogStash::Event.new({"nested" => {"this[embedded]legal" => "okay"}, "n[0]" => "bene"})
      expect(e.get('nested')).to eq({"this[embedded]legal" => "okay"})
      expect(e.to_hash).to include("n[0]" => "bene")
    end

runs without error.

@robbavey
Copy link
Member Author

This issue is superseded by #14821

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants