From e4bb8387952069cca9da06bbc5c87ae576c2bf6f Mon Sep 17 00:00:00 2001 From: Andy Patterson Date: Mon, 7 Dec 2015 17:02:15 +0000 Subject: [PATCH] fix(input): add missing chars to URL validation regex Update the list of permitted chars in URLs. Closes #13379 Closes #13460 --- src/ng/directive/input.js | 2 +- test/ng/directive/inputSpec.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index a51be30659a4..fdb52f0752db 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -12,7 +12,7 @@ // Regex code is obtained from SO: https://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime#answer-3143231 var ISO_DATE_REGEXP = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/; // See valid URLs in RFC3987 (http://tools.ietf.org/html/rfc3987) -var URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.?+=&%@\-/]*)?$/; +var URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.?+=&%@\-/[\]$'()*,;~]*)?$/; var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i; var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/; var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 207c71ce56e2..77ee82ec1a00 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -2544,11 +2544,13 @@ describe('input', function() { expect(URL_REGEXP.test('mailto:user@example.com?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://example.com/path;path')).toBe(true); + expect(URL_REGEXP.test('http://example.com/[]$\'()*,~)')).toBe(true); expect(URL_REGEXP.test('http:')).toBe(false); expect(URL_REGEXP.test('a@B.c')).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); + expect(URL_REGEXP.test('http://example.com:9999/``')).toBe(false); }); }); });