Skip to content

Commit ac06c6b

Browse files
committed
Added empty helper to validate URLs.
1 parent 2e8971f commit ac06c6b

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

src/service.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ function Repo() {
1616
this.isSuite = this.id in suites;
1717
}
1818

19+
function isUrl( str ) {
20+
// TOOD: URL validation
21+
return true;
22+
}
23+
1924
// package.json
2025
extend( Repo.prototype, {
2126
getPackageJson: function( version, file, fn ) {
@@ -84,9 +89,13 @@ extend( Repo.prototype, {
8489
if ( "email" in package.author && typeof package.author.email !== "string" ) {
8590
errors.push( "Invalid data type for author.email; must be a string." );
8691
}
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+
}
9099
}
91100
}
92101

@@ -96,9 +105,10 @@ extend( Repo.prototype, {
96105
errors.push( "There must be at least one license." );
97106
} else {
98107
package.licenses.forEach(function( license, i ) {
99-
// TDOO: verify url format
100108
if ( !license.url ) {
101109
errors.push( "Missing required field: licenses[" + i + "].url." );
110+
} else if ( !isUrl( license.url ) ) {
111+
errors.push( "Invalid value for license.url." );
102112
}
103113
});
104114
}
@@ -136,19 +146,28 @@ extend( Repo.prototype, {
136146
}
137147
}
138148

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+
}
142155
}
143156

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+
}
147163
}
148164

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+
}
152171
}
153172

154173
if ( "maintainers" in package ) {
@@ -163,9 +182,13 @@ extend( Repo.prototype, {
163182
if ( "email" in maintainer && typeof maintainer.email !== "string" ) {
164183
errors.push( "Invalid data type for maintainers[" + i + "].email; must be a string." );
165184
}
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+
}
169192
}
170193
});
171194
}

0 commit comments

Comments
 (0)