Browse files

the default path of cookies should be the request path minus any reso…

…urce at the requested path
  • Loading branch information...
1 parent a937f83 commit 76a540c752549cfe8d5781c247413a9f1fe8da13 @boblail boblail committed Jan 20, 2011
Showing with 4 additions and 1 deletion.
  1. +2 −0 spec/cookie-spec.coffee
  2. +2 −1 src/zombie/cookies.coffee
View
2 spec/cookie-spec.coffee
@@ -88,6 +88,7 @@ vows.describe("Cookies").addBatch(
browser.cookies("localhost", "/cookies/fido").set "_path4", "there", "path": "/cookies/fido"
browser.cookies("localhost", "/jars").set "_path5", "here", "path": "/cookies"
browser.cookies("localhost", "/jars").set "_path6", "here"
+ browser.cookies("localhost", "/jars/").set "_path7", "there"
browser.cookies(".localhost").set "_domain1", "here"
browser.cookies("not.localhost").set "_domain2", "there"
browser.cookies("notlocalhost").set "_domain3", "there"
@@ -109,6 +110,7 @@ vows.describe("Cookies").addBatch(
"should not pass unrelated path cookies to server": (cookies)->
assert.isUndefined cookies._path3
assert.isUndefined cookies._path4
+ assert.isUndefined cookies._path7
"should pass sub-domain cookies to server": (cookies)-> assert.equal cookies._domain1, "here"
"should not pass other domain cookies to server": (cookies)->
assert.isUndefined cookies._domain2
View
3 src/zombie/cookies.coffee
@@ -78,8 +78,9 @@ class Cookies
if typeof state.expires is "number" && state.expires <= browser.clock
@remove(name, options)
else
+ path_without_resource = pathname.match(/.*\//) # everything but what trails the last /
in_domain = cookies[options.domain || hostname] ||= {}
- in_path = in_domain[options.path || '/'] ||= {}
+ in_path = in_domain[options.path || path_without_resource] ||= {}
in_path[name] = state
#### cookies(host, path).remove(name, options?)

0 comments on commit 76a540c

Please sign in to comment.