Skip to content

Commit

Permalink
Merge pull request #1415 from puppetlabs/CAT-2155
Browse files Browse the repository at this point in the history
(CAT-2155) Remove metadata_syntax_validator parser swap to `JSON::Pure`
  • Loading branch information
gavindidrichsen authored Nov 8, 2024
2 parents 5efd5e9 + 01ce3e9 commit 8dcfbb5
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 8dcfbb5

Please sign in to comment.