multipart-parser 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +5 -0
- data/Rakefile +10 -0
- data/lib/multipart_parser/parser.rb +2 -2
- data/lib/multipart_parser/reader.rb +1 -1
- data/lib/multipart_parser/version.rb +1 -1
- data/test/fixtures/multipart.rb +32 -6
- data/test/multipart_parser/parser_test.rb +4 -5
- data/test/multipart_parser/{reader.rb → reader_test.rb} +35 -0
- metadata +7 -8
data/README
CHANGED
data/Rakefile
ADDED
@@ -22,7 +22,7 @@ module MultipartParser
|
|
22
22
|
|
23
23
|
@boundary_chars = {}
|
24
24
|
@boundary.each_byte do |b|
|
25
|
-
@boundary_chars[b] = true
|
25
|
+
@boundary_chars[b.chr] = true
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -137,7 +137,7 @@ module MultipartParser
|
|
137
137
|
# See http://debuggable.com/posts/parsing-file-uploads-at-500-
|
138
138
|
# mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb
|
139
139
|
while i + boundary_length <= buffer_length
|
140
|
-
break if boundary_chars.has_key? buffer[i + boundary_end]
|
140
|
+
break if boundary_chars.has_key? buffer[i + boundary_end].chr
|
141
141
|
i += boundary_length
|
142
142
|
end
|
143
143
|
c = buffer[i, 1]
|
data/test/fixtures/multipart.rb
CHANGED
@@ -10,7 +10,7 @@ module MultipartParser::Fixtures
|
|
10
10
|
def boundary
|
11
11
|
'AaB03x'
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def expect_error
|
15
15
|
false
|
16
16
|
end
|
@@ -22,7 +22,7 @@ module MultipartParser::Fixtures
|
|
22
22
|
part2[:headers] = {}
|
23
23
|
part2[:headers]['content-disposition'] = 'form-data; name="pics"; ' +
|
24
24
|
'filename="file1.txt"'
|
25
|
-
part2[:headers]['Content-Type'] = 'text/plain'
|
25
|
+
part2[:headers]['Content-Type'] = 'text/plain'
|
26
26
|
part2[:data] = "... contents of file1.txt ...\r"
|
27
27
|
[part1, part2]
|
28
28
|
end
|
@@ -59,11 +59,11 @@ module MultipartParser::Fixtures
|
|
59
59
|
part2[:headers] = {}
|
60
60
|
part2[:headers]['content-disposition'] = 'form-data; name="pics"; ' +
|
61
61
|
'filename="file1.txt"'
|
62
|
-
part2[:headers]['Content-Type'] = 'text/plain'
|
62
|
+
part2[:headers]['Content-Type'] = 'text/plain'
|
63
63
|
part2[:data] = "... contents of file1.txt ...\r"
|
64
64
|
[part1, part2]
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def raw
|
68
68
|
['--AaB03x',
|
69
69
|
'content-disposition: form-data; name="field1"',
|
@@ -79,15 +79,41 @@ module MultipartParser::Fixtures
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
class LongBoundary
|
83
|
+
def boundary
|
84
|
+
'----------------------------5c4dc587f69f'
|
85
|
+
end
|
86
|
+
|
87
|
+
def expect_error
|
88
|
+
false
|
89
|
+
end
|
90
|
+
|
91
|
+
def parts
|
92
|
+
part1 = {}
|
93
|
+
part1[:headers] = {'content-disposition' => 'form-data; name="field1"'}
|
94
|
+
part1[:data] = "Joe Blow\r\nalmost tricked you!"
|
95
|
+
[part1]
|
96
|
+
end
|
97
|
+
|
98
|
+
def raw
|
99
|
+
['----------------------------5c4dc587f69f',
|
100
|
+
'content-disposition: form-data; name="field1"',
|
101
|
+
'',
|
102
|
+
"Joe Blow\r\nalmost tricked you!",
|
103
|
+
'----------------------------5c4dc587f69f--'
|
104
|
+
].join("\r\n")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
82
108
|
class EmptyHeader
|
83
109
|
def boundary
|
84
110
|
'AaB03x'
|
85
111
|
end
|
86
|
-
|
112
|
+
|
87
113
|
def expect_error
|
88
114
|
true
|
89
115
|
end
|
90
|
-
|
116
|
+
|
91
117
|
def parts
|
92
118
|
[] # Should never be called
|
93
119
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "multipart_parser/parser"
|
3
|
+
require "fixtures/multipart"
|
4
4
|
|
5
5
|
module MultipartParser
|
6
6
|
class ParserTest < Test::Unit::TestCase
|
@@ -11,8 +11,7 @@ module MultipartParser
|
|
11
11
|
|
12
12
|
parser.init_with_boundary("abc")
|
13
13
|
assert_equal "\r\n--abc", parser.boundary
|
14
|
-
expected_bc = {
|
15
|
-
98 => true, 99 => true}
|
14
|
+
expected_bc = {"\r"=>true, "\n"=>true, "-"=>true, "a"=>true, "b"=>true, "c"=>true}
|
16
15
|
assert_equal expected_bc, parser.boundary_chars
|
17
16
|
end
|
18
17
|
|
@@ -85,7 +84,7 @@ module MultipartParser
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
unless got_error
|
88
|
-
|
87
|
+
assert_equal true, end_called
|
89
88
|
assert_equal fixture.parts, parts
|
90
89
|
else
|
91
90
|
assert fixture.expect_error,
|
@@ -70,5 +70,40 @@ module MultipartParser
|
|
70
70
|
assert_equal 'file1.txt', file[:part].filename
|
71
71
|
assert_equal fixture.parts.last[:data], file[:data]
|
72
72
|
end
|
73
|
+
|
74
|
+
def test_long
|
75
|
+
fixture = Fixtures::LongBoundary.new
|
76
|
+
reader = Reader.new(fixture.boundary)
|
77
|
+
on_error_called = false
|
78
|
+
parts = {}
|
79
|
+
|
80
|
+
reader.on_error do |err|
|
81
|
+
on_error_called = true
|
82
|
+
end
|
83
|
+
|
84
|
+
reader.on_part do |part|
|
85
|
+
part_entry = {:part => part, :data => '', :ended => false}
|
86
|
+
parts[part.name] = part_entry
|
87
|
+
part.on_data do |data|
|
88
|
+
part_entry[:data] << data
|
89
|
+
end
|
90
|
+
part.on_end do
|
91
|
+
part_entry[:ended] = true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
reader.write(fixture.raw)
|
96
|
+
|
97
|
+
assert !on_error_called
|
98
|
+
assert reader.ended?
|
99
|
+
|
100
|
+
assert_equal parts.size, fixture.parts.size
|
101
|
+
assert parts.all? {|k, v| v[:ended]}
|
102
|
+
|
103
|
+
field = parts['field1']
|
104
|
+
assert !field.nil?
|
105
|
+
assert_equal 'field1', field[:part].name
|
106
|
+
assert_equal fixture.parts.first[:data], field[:data]
|
107
|
+
end
|
73
108
|
end
|
74
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'multipart-parser is a simple parser for multipart MIME messages, written
|
15
15
|
in
|
@@ -40,13 +40,14 @@ extra_rdoc_files: []
|
|
40
40
|
files:
|
41
41
|
- LICENSE
|
42
42
|
- README
|
43
|
+
- Rakefile
|
43
44
|
- lib/multipart_parser/parser.rb
|
44
45
|
- lib/multipart_parser/reader.rb
|
45
46
|
- lib/multipart_parser/version.rb
|
46
47
|
- multipart-parser.gemspec
|
47
48
|
- test/fixtures/multipart.rb
|
48
49
|
- test/multipart_parser/parser_test.rb
|
49
|
-
- test/multipart_parser/
|
50
|
+
- test/multipart_parser/reader_test.rb
|
50
51
|
homepage: https://github.com/danabr/multipart-parser
|
51
52
|
licenses: []
|
52
53
|
post_install_message:
|
@@ -67,11 +68,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
version: '0'
|
68
69
|
requirements: []
|
69
70
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.24
|
71
72
|
signing_key:
|
72
73
|
specification_version: 3
|
73
74
|
summary: simple parser for multipart MIME messages
|
74
|
-
test_files:
|
75
|
-
|
76
|
-
- test/multipart_parser/parser_test.rb
|
77
|
-
- test/multipart_parser/reader.rb
|
75
|
+
test_files: []
|
76
|
+
has_rdoc:
|