diff --git a/src/spine.databind.coffee b/src/spine.databind.coffee index 894d04d..ebf026e 100644 --- a/src/spine.databind.coffee +++ b/src/spine.databind.coffee @@ -431,7 +431,8 @@ class Cookie extends Template keys: [ "cookie" ] @get: (sKey) -> - unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")) + regex = new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*") + return unescape(document.cookie.replace(regex, "$1")) if regex.test(document.cookie) @set: (sKey, sValue, vEnd, sPath, sDomain, bSecure) -> return if not sKey or /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey) @@ -458,7 +459,7 @@ class Cookie extends Template update: (operators,model,controller,el,options) -> for operator in operators value = @get(model,operator.property) - Cookie.set(operator.target,value) + Cookie.set(operator.target,value) if value and value isnt "undefined" change: (operators,model,controller,el,options) -> for operator in operators diff --git a/src/spine.databind.js b/src/spine.databind.js index 0f6cf4a..a015711 100644 --- a/src/spine.databind.js +++ b/src/spine.databind.js @@ -755,7 +755,11 @@ Cookie.prototype.keys = ["cookie"]; Cookie.get = function(sKey) { - return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")); + var regex; + regex = new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"); + if (regex.test(document.cookie)) { + return unescape(document.cookie.replace(regex, "$1")); + } }; Cookie.set = function(sKey, sValue, vEnd, sPath, sDomain, bSecure) { @@ -800,7 +804,11 @@ for (_i = 0, _len = operators.length; _i < _len; _i++) { operator = operators[_i]; value = this.get(model, operator.property); - _results.push(Cookie.set(operator.target, value)); + if (value && value !== "undefined") { + _results.push(Cookie.set(operator.target, value)); + } else { + _results.push(void 0); + } } return _results; };