Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
fix: JSON.load_file support for ruby 2.X
Browse files Browse the repository at this point in the history
  • Loading branch information
noraj committed Jun 9, 2021
1 parent db8f2ef commit bf4160f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

Fixes:

- `JSON.load_file()` is only available since Ruby 3.0 so `Utils.json_load_file()` was created to bring compatibility with Ruby 2.X

## [1.3.0]

Additions:
Expand Down
6 changes: 3 additions & 3 deletions lib/tls_map/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class << self
# See {TLSmap::App::Extractor}
# @return [Array<String>] Cipher array (IANA names)
def parse(file)
data = JSON.load_file(file)
data = Utils.json_load_file(file)
extract_cipher(data)
end

Expand Down Expand Up @@ -164,7 +164,7 @@ class << self
# See {TLSmap::App::Extractor}
# @return [Array<String>] Cipher array (IANA names)
def parse(file)
data = JSON.load_file(file)
data = Utils.json_load_file(file)
extract_cipher(data)
end

Expand Down Expand Up @@ -214,7 +214,7 @@ class << self
# See {TLSmap::App::Extractor}
# @return [Array<String>] Cipher array (IANA names)
def parse(file)
data = JSON.load_file(file)
data = Utils.json_load_file(file)
extract_cipher(data)
end

Expand Down
11 changes: 11 additions & 0 deletions lib/tls_map/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Ruby internal
require 'net/http'
require 'tempfile'
require 'json'

# TLS map module
module TLSmap
Expand All @@ -14,6 +15,16 @@ def tmpfile(name, url)
tmp.close
tmp
end

# bring JSON.load_file before ruby 3.0.0
# https://ruby-doc.org/stdlib-3.0.0/libdoc/json/rdoc/JSON.html#method-i-load_file
def self.json_load_file(filespec, opts = {})
if RUBY_VERSION < '3.0.0'
JSON.parse(File.read(filespec), opts)
else
JSON.load_file(filespec, opts)
end
end
end

# TLS mapping
Expand Down

0 comments on commit bf4160f

Please sign in to comment.