Skip to content

Commit

Permalink
Merge pull request #49 from airbnb/oj-strict-mode
Browse files Browse the repository at this point in the history
Load JSON objects in strict mode
  • Loading branch information
darnaut authored Jul 27, 2022
2 parents 05696d4 + 06b4aa3 commit 9426ed4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'oj'
Oj.default_options = { :mode => :strict }
opts = Oj.load( File.read('config.json') )

# prepare the logger
Expand Down
2 changes: 1 addition & 1 deletion optica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_nodes(request, fields_to_include=nil)

post '/' do
begin
data = Oj.load request.body.read
data = Oj.load(request.body.read, :mode => :strict)
rescue JSON::ParserError
data = {}
end
Expand Down
4 changes: 2 additions & 2 deletions store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def load_instances_from_leader
uri = "http://localhost:%d/store" % @opts['split_mode_store_port']
res = open(uri, :read_timeout => @opts['split_mode_http_timeout'])

remote_store = Oj.load res.read
remote_store = Oj.load(res.read, :mode => :strict)
[ remote_store['inst'], remote_store['idx'] ]
rescue OpenURI::HTTPError, Errno::ECONNREFUSED, Net::ReadTimeout => e
@log.error "Error loading store from #{uri}: #{e.inspect}; will retry after #{@opts['split_mode_retry_delay']}"
Expand Down Expand Up @@ -322,7 +322,7 @@ def get_node(node)
@zk.get(node)
end
STATSD.time('optica.json.parse') do
Oj.load(data)
Oj.load(data, :mode => :strict)
end
rescue ZK::Exceptions::NoNode
@log.info "node #{node} disappeared"
Expand Down

0 comments on commit 9426ed4

Please sign in to comment.