diff --git a/src/ng/location.js b/src/ng/location.js index 7b011abe9b57..0b869679c8ea 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -1,6 +1,6 @@ 'use strict'; -var SERVER_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?(\{?[\w\.-]*\}?)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/, +var SERVER_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?(\[(?:[0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}]|\{?[\w\.-]*\}?)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/, PATH_MATCH = /^([^\?#]*)(\?([^#]*))?(#(.*))?$/, DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21}; diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index ee920ed93e67..0b048d9112df 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -647,6 +647,27 @@ describe('$location', function() { expect(match[3]).toBe('www.angularjs.org'); }); + it('should parse valid IPv6 addresses', function() { + var match = SERVER_MATCH.exec('http://[1234:5678:a:b:c:d:e:f]/path'); + + expect(match[1]).toBe('http'); + expect(match[3]).toBe('[1234:5678:a:b:c:d:e:f]'); + expect(match[5]).toBeFalsy(); + expect(match[6]).toBe('/path'); + expect(match[8]).toBeFalsy(); + + match = SERVER_MATCH.exec('http://[::]/path'); + expect(match[3]).toBe('[::]'); + + match = SERVER_MATCH.exec('http://[1234:5678:b:a:d:b:a:d:112]/is-a-bad-ipv6'); + expect(match).toBe(null); + + match = SERVER_MATCH.exec('http://[:]/is-a-bad-ipv6'); + expect(match).toBe(null); + + match = SERVER_MATCH.exec('http://[::::::::::::::::::::::::::]/is-a-bad-ipv6'); + expect(match).toBe(null); + }); it('should parse file://', function() { var match = SERVER_MATCH.exec('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');