diff options
| author | Chirayu Krishnappa | 2013-07-15 12:26:46 -0700 | 
|---|---|---|
| committer | Chirayu Krishnappa | 2013-07-19 01:44:57 -0700 | 
| commit | b99d064b6ddbcc9f59ea45004279833e9ea82928 (patch) | |
| tree | 94406ce1926027de90a43b4abf4a7c7c8b0651c6 /src/ng/http.js | |
| parent | 715d97d5c87c9250f8ac8b5801b8c7f3b197e815 (diff) | |
| download | angular.js-b99d064b6ddbcc9f59ea45004279833e9ea82928.tar.bz2 | |
fix(core): parse URLs using the browser's DOM API
Diffstat (limited to 'src/ng/http.js')
| -rw-r--r-- | src/ng/http.js | 43 | 
1 files changed, 3 insertions, 40 deletions
| diff --git a/src/ng/http.js b/src/ng/http.js index a44da3a4..2aedeacb 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -29,43 +29,6 @@ function parseHeaders(headers) {  } -var IS_SAME_DOMAIN_URL_MATCH = /^(([^:]+):)?\/\/(\w+:{0,1}\w*@)?([\w\.-]*)?(:([0-9]+))?(.*)$/; - - -/** - * Parse a request and location URL and determine whether this is a same-domain request. - * - * @param {string} requestUrl The url of the request. - * @param {string} locationUrl The current browser location url. - * @returns {boolean} Whether the request is for the same domain. - */ -function isSameDomain(requestUrl, locationUrl) { -  var match = IS_SAME_DOMAIN_URL_MATCH.exec(requestUrl); -  // if requestUrl is relative, the regex does not match. -  if (match == null) return true; - -  var domain1 = { -      protocol: match[2], -      host: match[4], -      port: int(match[6]) || DEFAULT_PORTS[match[2]] || null, -      // IE8 sets unmatched groups to '' instead of undefined. -      relativeProtocol: match[2] === undefined || match[2] === '' -    }; - -  match = SERVER_MATCH.exec(locationUrl); -  var domain2 = { -      protocol: match[1], -      host: match[3], -      port: int(match[5]) || DEFAULT_PORTS[match[1]] || null -    }; - -  return (domain1.protocol == domain2.protocol || domain1.relativeProtocol) && -         domain1.host == domain2.host && -         (domain1.port == domain2.port || (domain1.relativeProtocol && -             domain2.port == DEFAULT_PORTS[domain2.protocol])); -} - -  /**   * Returns a function that provides access to parsed headers.   * @@ -168,8 +131,8 @@ function $HttpProvider() {     */    var responseInterceptorFactories = this.responseInterceptors = []; -  this.$get = ['$httpBackend', '$browser', '$cacheFactory', '$rootScope', '$q', '$injector', -      function($httpBackend, $browser, $cacheFactory, $rootScope, $q, $injector) { +  this.$get = ['$httpBackend', '$browser', '$cacheFactory', '$rootScope', '$q', '$injector', '$$urlUtils', +      function($httpBackend, $browser, $cacheFactory, $rootScope, $q, $injector, $$urlUtils) {      var defaultCache = $cacheFactory('$http'); @@ -657,7 +620,7 @@ function $HttpProvider() {        config.headers = headers;        config.method = uppercase(config.method); -      var xsrfValue = isSameDomain(config.url, $browser.url()) +      var xsrfValue = $$urlUtils.isSameOrigin(config.url)            ? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName]            : undefined;        if (xsrfValue) { | 
