Skip to content

Commit 53275e7

Browse files
authored
Merge pull request #12 from haacked/loosen-url-validation
Be less restrictive when validating urls
2 parents 4339d62 + e9197fa commit 53275e7

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-client-validation",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Enables ASP.NET MVC client-side validation, without jQuery!",
55
"main": "dist/aspnet-validation.js",
66
"style": "dist/aspnet-validation.css",

src/index.ts

+6-41
Original file line numberDiff line numberDiff line change
@@ -235,48 +235,13 @@ export class MvcValidationProviders {
235235
if (!value) {
236236
return true;
237237
}
238+
239+
let lowerCaseValue = value.toLowerCase();
238240

239-
// (c) Diego Perini, MIT Licensed
240-
// https://gist.github.com/dperini/729294
241-
242-
var r = new RegExp(
243-
"^" +
244-
// protocol identifier
245-
"(?:(?:https?|ftp)://)" +
246-
// user:pass authentication
247-
"(?:\\S+(?::\\S*)?@)?" +
248-
"(?:" +
249-
// IP address exclusion
250-
// private & local networks
251-
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
252-
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
253-
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
254-
// IP address dotted notation octets
255-
// excludes loopback network 0.0.0.0
256-
// excludes reserved space >= 224.0.0.0
257-
// excludes network & broacast addresses
258-
// (first & last IP address of each class)
259-
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
260-
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
261-
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
262-
"|" +
263-
// host name
264-
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
265-
// domain name
266-
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
267-
// TLD identifier
268-
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
269-
// TLD may end with dot
270-
"\\.?" +
271-
")" +
272-
// port number
273-
"(?::\\d{2,5})?" +
274-
// resource path
275-
"(?:[/?#]\\S*)?" +
276-
"$", "i"
277-
);
278-
279-
return r.test(value);
241+
// Match the logic in `UrlAttribute`
242+
return lowerCaseValue.indexOf('http://') > -1
243+
|| lowerCaseValue.indexOf('https://') > -1
244+
|| lowerCaseValue.indexOf('ftp://') > -1;
280245
}
281246

282247
/**

0 commit comments

Comments
 (0)