Skip to content

Commit

Permalink
Load JSON objects in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
darnaut committed Jul 27, 2022
1 parent 05696d4 commit 06b4aa3
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 06b4aa3

Please sign in to comment.