File: webagent-0_6_2_cookie_rb_patch.diff

package info (click to toggle)
libhttp-access2-ruby 2.0.6-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 228 kB
  • ctags: 336
  • sloc: ruby: 3,008; makefile: 50
file content (77 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- cookie.rb	2002-09-30 01:00:39.000000000 +0900
+++ ../../../lib/http-access2/cookie.rb	2005-09-01 21:13:10.452454400 +0900
@@ -1,2 +1,8 @@
+# cookie.rb is redistributed file which is originally included in Webagent
+# version 0.6.2 by TAKAHASHI `Maki' Masayoshi.  And it contains some bug fixes.
+# You can download the entire package of Webagent from
+# http://www.rubycolor.org/arc/.
+
+
 # Cookie class
 #
@@ -64,4 +70,5 @@ class WebAgent
 
     def initialize()
+      @discard = @use = @secure = @domain_orig = @path_orig = @override = nil
     end
 
@@ -168,8 +175,7 @@ class WebAgent
 	key, value = pair.split(/=/)  ## value may nil
 	key.strip!
-	value.strip!
-	if value && value =~ /^"(.*)"$/
-	  value = $1
-	end
+        if value
+          value = value.strip.sub(/\A"(.*)"\z/) { $1 }
+        end
 	case key.downcase
 	when 'domain'
@@ -207,4 +213,5 @@ class WebAgent
     attr_accessor :cookies_file
     attr_accessor :accept_domains, :reject_domains
+    attr_accessor :require_three_periods_in_domain
 
     def initialize(file=nil)
@@ -214,13 +221,16 @@ class WebAgent
       @reject_domains = Array.new()
       @accept_domains = Array.new()
+      # for conformance to http://wp.netscape.com/newsref/std/cookie_spec.html
+      @require_three_periods_in_domain = true
     end
 
-    def save_cookies(force = nil)
-      if @is_saved && !force
+    def save_all_cookies(force = nil, save_unused = true, save_discarded = true)
+      if @is_saved and !force
 	return
       end
-      File.open(@cookies_file,'w'){|f|
-	@cookies.each{|cookie|
-	  if cookie.use? && (!cookie.discard?)
+      File.open(@cookies_file, 'w') do |f|
+	@cookies.each do |cookie|
+          if (cookie.use? or save_unused) and
+              (!cookie.discard? or save_discarded)
 	    f.print(cookie.url.to_s,"\t",
 		    cookie.name,"\t",
@@ -231,6 +241,10 @@ class WebAgent
 		    cookie.flag,"\n")
 	  end
-	}
-      }
+        end
+      end
+    end
+
+    def save_cookies(force = nil)
+      save_all_cookies(force, false, false)
     end
 
@@ -334,5 +348,5 @@ class WebAgent
 	    sdomain == domain[-(sdomain.length)..-1]
 	  }
-	  if ok.empty?
+	  if ok.empty? and @require_three_periods_in_domain
 	    cookie_error(SpecialError.new(), override)
 	  end