Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
the default path of cookies should be the request path minus any reso…
Browse files Browse the repository at this point in the history
…urce at the requested path
  • Loading branch information
boblail committed Jan 20, 2011
1 parent a937f83 commit 76a540c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/cookie-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/zombie/cookies.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down

0 comments on commit 76a540c

Please sign in to comment.