File tree Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 8
8
9
9
module MetadataJsonLint
10
10
MIN_PUPPET_VER = '4.10.0' . freeze
11
+ # Regex looks for:
12
+ # 1. Invalid escape sequences (\x or incomplete \u)
13
+ INVALID_ESCAPE_REGEX = %r{\\ [^"/bfnrtu]|\\ u(?![0-9a-fA-F]{4})} . freeze
11
14
12
15
def options
13
16
@options ||= Struct . new (
@@ -69,6 +72,11 @@ def run
69
72
end
70
73
module_function :run
71
74
75
+ def contains_invalid_escape? ( content )
76
+ content . match? ( INVALID_ESCAPE_REGEX )
77
+ end
78
+ module_function :contains_invalid_escape?
79
+
72
80
def parse ( metadata )
73
81
@errors = [ ]
74
82
@warnings = [ ]
@@ -83,6 +91,8 @@ def parse(metadata)
83
91
abort ( "Error: Unable to read metadata file: #{ e . exception } " )
84
92
end
85
93
94
+ abort ( 'Error: Unable to parse metadata.json: Invalid escape character in string' ) if contains_invalid_escape? ( f )
95
+
86
96
begin
87
97
parsed = JSON . parse ( f )
88
98
rescue Exception => e
Original file line number Diff line number Diff line change
1
+ $LOAD_PATH. unshift ( File . expand_path ( '../../lib' , __dir__ ) )
2
+ require 'metadata-json-lint/rake_task'
Original file line number Diff line number Diff line change
1
+ Error: Unable to parse metadata.json: Invalid escape character in string
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " puppetlabs-postgresql" ,
3
+ "version" : " 3.4.1" ,
4
+ "author" : " Inkling/Puppet Labs" ,
5
+ "summary" : " A description with an invalid \( escape sequence" ,
6
+ "license" : " Apache-2.0" ,
7
+ "source" : " git://github.com/puppetlabs/puppet-postgresql.git" ,
8
+ "project_page" : " https://github.com/puppetlabs/puppet-postgresql" ,
9
+ "issues_url" : " https://github.com/puppetlabs/puppet-postgresql/issues" ,
10
+ "operatingsystem_support" : [
11
+ ],
12
+ "requirements" : [
13
+ ],
14
+ "dependencies" : [
15
+ ]
16
+ }
Original file line number Diff line number Diff line change @@ -103,6 +103,9 @@ test "bad_license" $SUCCESS --no-strict-license
103
103
# Run with --no-fail-on-warnings, expect SUCCESS
104
104
test " bad_license" $SUCCESS --no-fail-on-warnings
105
105
106
+ # Run a broken one, expect FAILURE
107
+ test " invalid_escape_char" $FAILURE
108
+
106
109
# Run a broken one, expect FAILURE
107
110
test " long_summary" $FAILURE
108
111
You can’t perform that action at this time.
0 commit comments