diff --git a/lib/metadata_json_lint.rb b/lib/metadata_json_lint.rb index 3571a20..dd54ad5 100644 --- a/lib/metadata_json_lint.rb +++ b/lib/metadata_json_lint.rb @@ -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 = [] @@ -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 diff --git a/tests/missing_newline/Rakefile b/tests/missing_newline/Rakefile new file mode 100644 index 0000000..c64525a --- /dev/null +++ b/tests/missing_newline/Rakefile @@ -0,0 +1,2 @@ +$LOAD_PATH.unshift(File.expand_path('../../lib', __dir__)) +require 'metadata-json-lint/rake_task' diff --git a/tests/missing_newline/expected b/tests/missing_newline/expected new file mode 100644 index 0000000..80656e9 --- /dev/null +++ b/tests/missing_newline/expected @@ -0,0 +1 @@ +Error: metadata.json does not have a valid newline at the end diff --git a/tests/missing_newline/metadata.json b/tests/missing_newline/metadata.json new file mode 100644 index 0000000..88df379 --- /dev/null +++ b/tests/missing_newline/metadata.json @@ -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": [ + ] +} \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh index 93a5965..1eb576d 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -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