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

Check if safe_load is defined on YAML before using it #1455

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gem 'sidekiq', require: nil
gem 'simplecov', require: false
gem 'simplecov-cobertura', require: false
gem 'sucker_punch', '~> 2.0', require: nil
gem 'syck', require: nil if !defined?(JRUBY_VERSION)
gem 'yard', require: nil
gem 'yarjuf'

Expand Down Expand Up @@ -125,10 +126,8 @@ if RUBY_PLATFORM == 'java'
end
elsif frameworks_versions['rails'] =~ /^(4|5)/
gem 'sqlite3', '~> 1.3.6'
elsif RUBY_VERSION < '2.7'
gem 'sqlite3', '~> 1.4.4'
else
gem 'sqlite3'
gem 'sqlite3', '~> 1.4.4'
end

# sneakers main only supports >=2.5.0
Expand Down
2 changes: 1 addition & 1 deletion lib/elastic_apm/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def load_config_file

read = File.read(config_file)
evaled = ERB.new(read).result
YAML.safe_load(evaled)
YAML.method_defined?(:safe_load) ? YAML.safe_load(evaled) : YAML.load(evaled)
end

def load_env
Expand Down
31 changes: 31 additions & 0 deletions spec/integration/syck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# frozen_string_literal: true

if !defined?(JRUBY_VERSION)
require 'integration_helper'
require 'syck'

RSpec.describe 'Syck YAML' do

it 'loads from config file' do
config = ElasticAPM::Config.new(config_file: 'spec/fixtures/elastic_apm.yml')
expect(config.server_url).to eq 'somewhere-config.com'
end
end
end
Loading