Skip to content

Commit

Permalink
Merge pull request #59 from bf4/master
Browse files Browse the repository at this point in the history
remove safe_yaml. Psych.safe_load is fine for modern rubies
  • Loading branch information
jnunemaker committed Dec 7, 2018
2 parents 1183581 + a7189fe commit 4ecf9cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
2 changes: 0 additions & 2 deletions crack.gemspec
Expand Up @@ -14,6 +14,4 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Crack::VERSION
gem.license = "MIT"

gem.add_dependency "safe_yaml", "~> 1.0.0"
end
23 changes: 5 additions & 18 deletions lib/crack/json.rb
Expand Up @@ -3,34 +3,21 @@
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

require 'safe_yaml/load'
require 'strscan'

module Crack
class JSON
def self.parser_exceptions
@parser_exceptions ||= begin
exceptions = [ArgumentError]

if const_defined?(:Psych)
if Psych.const_defined?(:SyntaxError)
exceptions << Psych::SyntaxError
end
end

exceptions
end
@parser_exceptions ||= [ArgumentError, Psych::SyntaxError]
end

def self.parse(json)
args = [unescape(convert_json_to_yaml(json))]
args << nil if SafeYAML::MULTI_ARGUMENT_YAML_LOAD
args << { :whitelisted_tags => ['!ruby/regexp'] }

SafeYAML.load(*args)

yaml = unescape(convert_json_to_yaml(json))
YAML.safe_load(yaml, [Regexp, Date, Time])
rescue *parser_exceptions
raise ParseError, "Invalid JSON string"
rescue Psych::DisallowedClass
yaml
end

protected
Expand Down

0 comments on commit 4ecf9cf

Please sign in to comment.