@@ -16,6 +16,11 @@ function Repo() {
16
16
this . isSuite = this . id in suites ;
17
17
}
18
18
19
+ function isUrl ( str ) {
20
+ // TOOD: URL validation
21
+ return true ;
22
+ }
23
+
19
24
// package.json
20
25
extend ( Repo . prototype , {
21
26
getPackageJson : function ( version , file , fn ) {
@@ -84,9 +89,13 @@ extend( Repo.prototype, {
84
89
if ( "email" in package . author && typeof package . author . email !== "string" ) {
85
90
errors . push ( "Invalid data type for author.email; must be a string." ) ;
86
91
}
87
- // TODO: verify url format
88
- if ( "url" in package . author && typeof package . author . url !== "string" ) {
89
- errors . push ( "Invalid data type for author.url; must be a string." ) ;
92
+
93
+ if ( "url" in package . author ) {
94
+ if ( typeof package . author . url !== "string" ) {
95
+ errors . push ( "Invalid data type for author.url; must be a string." ) ;
96
+ } else if ( ! isUrl ( package . author . url ) ) {
97
+ errors . push ( "Invalid value for author.url." ) ;
98
+ }
90
99
}
91
100
}
92
101
@@ -96,9 +105,10 @@ extend( Repo.prototype, {
96
105
errors . push ( "There must be at least one license." ) ;
97
106
} else {
98
107
package . licenses . forEach ( function ( license , i ) {
99
- // TDOO: verify url format
100
108
if ( ! license . url ) {
101
109
errors . push ( "Missing required field: licenses[" + i + "].url." ) ;
110
+ } else if ( ! isUrl ( license . url ) ) {
111
+ errors . push ( "Invalid value for license.url." ) ;
102
112
}
103
113
} ) ;
104
114
}
@@ -136,19 +146,28 @@ extend( Repo.prototype, {
136
146
}
137
147
}
138
148
139
- // TODO: verify url format
140
- if ( "homepage" in package && typeof package . homepage !== "string" ) {
141
- errors . push ( "Invalid data type for homepage; must be a string." ) ;
149
+ if ( "homepage" in package ) {
150
+ if ( typeof package . homepage !== "string" ) {
151
+ errors . push ( "Invalid data type for homepage; must be a string." ) ;
152
+ } else if ( ! isUrl ( package . homepage ) ) {
153
+ errors . push ( "Invalid value for homepage." ) ;
154
+ }
142
155
}
143
156
144
- // TODO: verify url format
145
- if ( "docs" in package && typeof package . docs !== "string" ) {
146
- errors . push ( "Invalid data type for docs; must be a string." ) ;
157
+ if ( "docs" in package ) {
158
+ if ( typeof package . docs !== "string" ) {
159
+ errors . push ( "Invalid data type for docs; must be a string." ) ;
160
+ } else if ( ! isUrl ( package . docs ) ) {
161
+ errors . push ( "Invalid value for docs." ) ;
162
+ }
147
163
}
148
164
149
- // TODO: verify url format
150
- if ( "demo" in package && typeof package . demo !== "string" ) {
151
- errors . push ( "Invalid data type for demo; must be a string." ) ;
165
+ if ( "demo" in package ) {
166
+ if ( typeof package . demo !== "string" ) {
167
+ errors . push ( "Invalid data type for demo; must be a string." ) ;
168
+ } else if ( ! isUrl ( package . demo ) ) {
169
+ errors . push ( "Invalid value for demo." ) ;
170
+ }
152
171
}
153
172
154
173
if ( "maintainers" in package ) {
@@ -163,9 +182,13 @@ extend( Repo.prototype, {
163
182
if ( "email" in maintainer && typeof maintainer . email !== "string" ) {
164
183
errors . push ( "Invalid data type for maintainers[" + i + "].email; must be a string." ) ;
165
184
}
166
- // TODO: verify url format
167
- if ( "url" in maintainer && typeof maintainer . url !== "string" ) {
168
- errors . push ( "Invalid data type for maintainers[" + i + "].url; must be a string." ) ;
185
+
186
+ if ( "url" in maintainer ) {
187
+ if ( typeof maintainer . url !== "string" ) {
188
+ errors . push ( "Invalid data type for maintainers[" + i + "].url; must be a string." ) ;
189
+ } else if ( ! isUrl ( maintainer . url ) ) {
190
+ errors . push ( "Invalid value for maintainers[" + i + "].url." ) ;
191
+ }
169
192
}
170
193
} ) ;
171
194
}
0 commit comments