This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngInput): change URL_REGEXP to better match RFC3987
The URL_REGEXP in use to perform validation in ngInput is too restrictive and fails to follow RFC3987. In particular, it only accepts ftp, http, and https scheme components and rejects perfectly valid schemes such as "file", "mailto", "chrome-extension", etc. The regex also requires the scheme to be followed by two "/" but the RFC says 0 to n are acceptable. This change fixes both of these issues to better align to the standard. Closes #11341 Closes #11381
- Loading branch information
1 parent
941c1c3
commit ffb6b2f
Showing
2 changed files
with
12 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2537,8 +2537,18 @@ describe('input', function() { | |
describe('URL_REGEXP', function() { | ||
/* global URL_REGEXP: false */ | ||
it('should validate url', function() { | ||
// See valid URLs in RFC3987 (http://tools.ietf.org/html/rfc3987) | ||
expect(URL_REGEXP.test('http://server:123/path')).toBe(true); | ||
expect(URL_REGEXP.test('https://server:123/path')).toBe(true); | ||
expect(URL_REGEXP.test('file:///home/user')).toBe(true); | ||
expect(URL_REGEXP.test('mailto:[email protected]?subject=Foo')).toBe(true); | ||
expect(URL_REGEXP.test('r2-d2.c3-p0://localhost/foo')).toBe(true); | ||
expect(URL_REGEXP.test('abc:/foo')).toBe(true); | ||
expect(URL_REGEXP.test('http:')).toBe(false); | ||
expect(URL_REGEXP.test('[email protected]')).toBe(false); | ||
expect(URL_REGEXP.test('a_B.c')).toBe(false); | ||
expect(URL_REGEXP.test('0scheme://example.com')).toBe(false); | ||
expect(URL_REGEXP.test('http://example.com:9999/~~``')).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
ffb6b2f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ngInput
isn't a commit message scope, we need to adjust that in the changelog for the next versionffb6b2f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I only realised after I had landed it. Sorry!