Skip to content

Commit

Permalink
Merge pull request #154 from bastelfreak/slashn
Browse files Browse the repository at this point in the history
Fail if metadata.json has no proper newline
  • Loading branch information
bastelfreak authored Jan 24, 2025
2 parents e9d088e + 6a5293d commit cd27d48
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/metadata_json_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def contains_invalid_escape?(content)
end
module_function :contains_invalid_escape?

def misses_newline_at_end?(content)
content[-1] != "\n"
end
module_function :misses_newline_at_end?

def parse(metadata)
@errors = []
@warnings = []
Expand All @@ -91,6 +96,8 @@ def parse(metadata)
abort("Error: Unable to read metadata file: #{e.exception}")
end

abort('Error: metadata.json does not have a valid newline at the end') if misses_newline_at_end?(f)

abort('Error: Unable to parse metadata.json: Invalid escape character in string') if contains_invalid_escape?(f)

begin
Expand Down
2 changes: 2 additions & 0 deletions tests/missing_newline/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
require 'metadata-json-lint/rake_task'
1 change: 1 addition & 0 deletions tests/missing_newline/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: metadata.json does not have a valid newline at the end
16 changes: 16 additions & 0 deletions tests/missing_newline/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "puppetlabs-postgresql",
"version": "3.4.1",
"author": "Inkling/Puppet Labs",
"summary": "A metadata.json file without a newline at the end",
"license": "Apache-2.0",
"source": "git://github.com/puppetlabs/puppet-postgresql.git",
"project_page": "https://github.com/puppetlabs/puppet-postgresql",
"issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
"operatingsystem_support": [
],
"requirements": [
],
"dependencies": [
]
}
3 changes: 3 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ test "bad_license" $SUCCESS --no-fail-on-warnings
# Run a broken one, expect FAILURE
test "invalid_escape_char" $FAILURE

# Run a broken one, expect FAILURE
test "missing_newline" $FAILURE

# Run a broken one, expect FAILURE
test "long_summary" $FAILURE

Expand Down

0 comments on commit cd27d48

Please sign in to comment.