File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: binary -*-
2
+ require 'cgi'
2
3
require 'uri'
3
4
require 'rex/proto/http'
4
5
require 'nokogiri'
@@ -84,6 +85,18 @@ def get_cookies
84
85
return cookies . strip
85
86
end
86
87
88
+ #
89
+ # Gets cookies from the Set-Cookie header in a parsed format
90
+ #
91
+ def get_cookies_parsed
92
+ if ( self . headers . include? ( 'Set-Cookie' ) )
93
+ ret = CGI ::Cookie ::parse ( self . headers [ 'Set-Cookie' ] )
94
+ else
95
+ ret = { }
96
+ end
97
+ ret
98
+ end
99
+
87
100
88
101
# Returns a parsed HTML document.
89
102
# Instead of using regexes to parse the HTML body, you should use this and use the Nokogiri API.
Original file line number Diff line number Diff line change 133
133
HEREDOC
134
134
end
135
135
136
+ let ( :get_cookies_spaces_and_missing_semicolon ) do
137
+ <<-HEREDOC . gsub ( /^ {6}/ , '' )
138
+ HTTP/1.1 200 OK
139
+ Set-Cookie: k1=v1; k2=v2;k3=v3
140
+
141
+ HEREDOC
142
+ end
143
+
136
144
let ( :meta_name ) do
137
145
'META_NAME'
138
146
end
176
184
<genre>Computer</genre>
177
185
<price>44.95</price>
178
186
<publish_date>2000-10-01</publish_date>
179
- <description>An in-depth look at creating applications
187
+ <description>An in-depth look at creating applications
180
188
with XML.</description>
181
189
</book>
182
190
</catalog>
@@ -396,6 +404,22 @@ def cookie_sanity_check(meth)
396
404
expect ( cookies_array ) . to include ( *expected_cookies )
397
405
end
398
406
407
+ it 'parses cookies with inconsistent spacing and a missing trailing semicolons' do
408
+ resp = described_class . new ( )
409
+ resp . parse ( self . send :get_cookies_spaces_and_missing_semicolon )
410
+ cookies = resp . get_cookies_parsed
411
+ names = cookies . keys . sort
412
+ values = [ ]
413
+ cookies . each do |_ , parsed |
414
+ parsed . value . each do |value |
415
+ values << value
416
+ end
417
+ end
418
+ values . sort!
419
+ expect ( names ) . to eq ( %w( k1 k2 k3 ) )
420
+ expect ( values ) . to eq ( %w( v1 v2 v3 ) )
421
+ end
422
+
399
423
end
400
424
401
425
end
You can’t perform that action at this time.
0 commit comments