@@ -21,6 +21,10 @@ function isUrl( str ) {
21
21
return true ;
22
22
}
23
23
24
+ function isEmail ( str ) {
25
+ return ( / ^ [ a - z A - Z 0 - 9 . ! # $ % & ' * + \/ = ? \^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 - ] + (?: \. [ a - z A - Z 0 - 9 - ] + ) * $ / ) . test ( str ) ;
26
+ }
27
+
24
28
// package.json
25
29
extend ( Repo . prototype , {
26
30
getPackageJson : function ( version , file , fn ) {
@@ -101,9 +105,13 @@ extend( Repo.prototype, {
101
105
if ( typeof package . author . name !== "string" ) {
102
106
errors . push ( "Invalid data type for author.name; must be a string." ) ;
103
107
}
104
- // TODO: verify email address format
105
- if ( "email" in package . author && typeof package . author . email !== "string" ) {
106
- errors . push ( "Invalid data type for author.email; must be a string." ) ;
108
+
109
+ if ( "email" in package . author ) {
110
+ if ( typeof package . author . email !== "string" ) {
111
+ errors . push ( "Invalid data type for author.email; must be a string." ) ;
112
+ } else if ( ! isEmail ( package . author . email ) ) {
113
+ errors . push ( "Invalid value for author.email." ) ;
114
+ }
107
115
}
108
116
109
117
if ( "url" in package . author ) {
@@ -196,9 +204,13 @@ extend( Repo.prototype, {
196
204
if ( typeof maintainer . name !== "string" ) {
197
205
errors . push ( "Invalid data type for maintainers[" + i + "].name; must be a string." ) ;
198
206
}
199
- // TODO: verify email address format
200
- if ( "email" in maintainer && typeof maintainer . email !== "string" ) {
201
- errors . push ( "Invalid data type for maintainers[" + i + "].email; must be a string." ) ;
207
+
208
+ if ( "email" in maintainer ) {
209
+ if ( typeof maintainer . email !== "string" ) {
210
+ errors . push ( "Invalid data type for maintainers[" + i + "].email; must be a string." ) ;
211
+ } else if ( ! isEmail ( maintainer . email ) ) {
212
+ errors . push ( "Invalid value for maintainers[" + i + "].email." ) ;
213
+ }
202
214
}
203
215
204
216
if ( "url" in maintainer ) {
0 commit comments