Skip to content

Commit 4e1eb01

Browse files
committed
fix(input):URL validation does not recognize URLs with no protocol
change the url regexp to recognize urls without protocol closes angular#6634
1 parent d1214af commit 4e1eb01

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-DIRTY_CLASS
99
*/
1010

11-
var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
11+
var URL_REGEXP = /^(((ftp|https?):\/\/)(www\.)?|www\.)([\da-z-_\.]+)([a-z\.]{2,7})([\/\w\.-_\?\&#]*)*\/?$/;
1212
var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
1313
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
1414
var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/;

test/ng/directive/inputSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,22 @@ describe('input', function() {
16971697
expect(URL_REGEXP.test('http://server:123/path')).toBe(true);
16981698
expect(URL_REGEXP.test('[email protected]')).toBe(false);
16991699
});
1700+
1701+
1702+
it('should pass on valid url', function() {
1703+
expect(URL_REGEXP.test('http://server:123/path')).toBe(true);
1704+
expect(URL_REGEXP.test('http://foo.com/angular#directives')).toBe(true);
1705+
expect(URL_REGEXP.test('www.angularjs.org')).toBe(true);
1706+
expect(URL_REGEXP.test('http://localhost:8080/?angular=cool&i=loveit')).toBe(true);
1707+
});
1708+
1709+
1710+
it('should fail on invalid url', function() {
1711+
expect(URL_REGEXP.test('http://')).toBe(false);
1712+
expect(URL_REGEXP.test('http://w')).toBe(false);
1713+
expect(URL_REGEXP.test('http://www.angularjs. org')).toBe(false);
1714+
expect(URL_REGEXP.test('htp://localhost:8080/?angular=cool&i=loveit')).toBe(false);
1715+
});
17001716
});
17011717
});
17021718

0 commit comments

Comments
 (0)