Skip to content

Commit

Permalink
(CAT-2155) Remove parser swap to JSON::Pure
Browse files Browse the repository at this point in the history
`JSON::Pure` no longer exists within the `json` gem as of `2.8.0` and as such this swap has to be removed.
  • Loading branch information
david22swan committed Nov 8, 2024
1 parent 5efd5e9 commit 01ce3e9
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 15 deletions.
13 changes: 1 addition & 12 deletions lib/pdk/validate/metadata/metadata_syntax_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ def invoke(report)
JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
end

def before_validation
# The pure ruby JSON parser gives much nicer parse error messages than
# the C extension at the cost of slightly slower parsing. We require it
# here and restore the C extension at the end of the method (if it was
# being used).
require 'json/pure'
JSON.parser = JSON::Pure::Parser
end

def validate_target(report, target)
unless PDK::Util::Filesystem.readable?(target)
report.add_event(
Expand All @@ -56,9 +47,7 @@ def validate_target(report, target)
rescue JSON::ParserError => e
# Because the message contains a raw segment of the file, we use
# String#dump here to unescape any escape characters like newlines.
# We then strip out the surrounding quotes and the exclaimation
# point that json_pure likes to put in exception messages.
sane_message = e.message.dump[/\A"(.+?)!?"\Z/, 1]
sane_message = e.message.dump

report.add_event(
file: target,
Expand Down
1 change: 0 additions & 1 deletion pdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Gem::Specification.new do |spec|
# Other deps
spec.add_runtime_dependency 'deep_merge', '~> 1.2.2'
spec.add_runtime_dependency 'diff-lcs', '>= 1.5.0'
spec.add_runtime_dependency 'json', '< 2.8.0'
spec.add_runtime_dependency 'pathspec', '~> 1.1'
spec.add_runtime_dependency 'puppet_forge', '~> 5.0'

Expand Down
2 changes: 1 addition & 1 deletion spec/support/file_based_namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@

context 'when there is no data stored' do
it 'serializes to an empty JSON object' do
expect(serialized_data).to match(/^\{\n+\}$/)
expect(serialized_data).to match(/^\{\}$/)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
source: 'metadata-syntax',
state: :failure,
severity: 'error',
message: a_string_matching(/\Aexpected ':' in object/)
message: a_string_matching(/unexpected token at/)
})
expect(return_value).to eq(1)
end
Expand Down

0 comments on commit 01ce3e9

Please sign in to comment.