aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/browser.js
diff options
context:
space:
mode:
authorMisko Hevery2012-05-03 14:52:26 -0700
committerMisko Hevery2012-05-04 15:50:39 -0700
commitd0159454dfa2e1cee4dd4ab7a41c2fcf9e121a64 (patch)
tree053d7cdd1e0501a28ce0cb30992aa4a2e7cdf15f /src/ng/browser.js
parent7f0eb1516165fcb73f1c9953018b7c9b70acfae1 (diff)
downloadangular.js-d0159454dfa2e1cee4dd4ab7a41c2fcf9e121a64.tar.bz2
bug($cookie): set on app base path rather the current path.
Diffstat (limited to 'src/ng/browser.js')
-rw-r--r--src/ng/browser.js42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/ng/browser.js b/src/ng/browser.js
index fe14a3d7..9dce89db 100644
--- a/src/ng/browser.js
+++ b/src/ng/browser.js
@@ -17,12 +17,11 @@
/**
* @param {object} window The global window object.
* @param {object} document jQuery wrapped document.
- * @param {object} body jQuery wrapped document.body.
* @param {function()} XHR XMLHttpRequest constructor.
* @param {object} $log console.log or an object with the same interface.
* @param {object} $sniffer $sniffer service
*/
-function Browser(window, document, body, $log, $sniffer) {
+function Browser(window, document, $log, $sniffer) {
var self = this,
rawDocument = document[0],
location = window.location,
@@ -222,10 +221,26 @@ function Browser(window, document, body, $log, $sniffer) {
};
//////////////////////////////////////////////////////////////
+ // Misc API
+ //////////////////////////////////////////////////////////////
+
+ /**
+ * Returns current <base href>
+ * (always relative - without domain)
+ *
+ * @returns {string=}
+ */
+ self.baseHref = function() {
+ var href = document.find('base').attr('href');
+ return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href;
+ };
+
+ //////////////////////////////////////////////////////////////
// Cookies API
//////////////////////////////////////////////////////////////
var lastCookies = {};
var lastCookieString = '';
+ var cookiePath = self.baseHref();
/**
* @ngdoc method
@@ -253,12 +268,10 @@ function Browser(window, document, body, $log, $sniffer) {
if (name) {
if (value === undefined) {
- rawDocument.cookie = escape(name) + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
+ rawDocument.cookie = escape(name) + "=;path=" + cookiePath + ";expires=Thu, 01 Jan 1970 00:00:00 GMT";
} else {
if (isString(value)) {
- rawDocument.cookie = escape(name) + '=' + escape(value);
-
- cookieLength = name.length + value.length + 1;
+ cookieLength = (rawDocument.cookie = escape(name) + '=' + escape(value) + ';path=' + cookiePath).length + 1;
if (cookieLength > 4096) {
$log.warn("Cookie '"+ name +"' possibly not set or overflowed because it was too large ("+
cookieLength + " > 4096 bytes)!");
@@ -338,26 +351,11 @@ function Browser(window, document, body, $log, $sniffer) {
return false;
};
-
- //////////////////////////////////////////////////////////////
- // Misc API
- //////////////////////////////////////////////////////////////
-
- /**
- * Returns current <base href>
- * (always relative - without domain)
- *
- * @returns {string=}
- */
- self.baseHref = function() {
- var href = document.find('base').attr('href');
- return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : href;
- };
}
function $BrowserProvider(){
this.$get = ['$window', '$log', '$sniffer', '$document',
function( $window, $log, $sniffer, $document){
- return new Browser($window, $document, $document.find('body'), $log, $sniffer);
+ return new Browser($window, $document, $log, $sniffer);
}];
}