zero-fix18 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --order random
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - 1.8.7
10
+ script: thor spec
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-bundler'
8
+ gem 'guard-rspec'
9
+ end
10
+
11
+ group :test do
12
+ gem 'thor'
13
+ gem 'rspec'
14
+ gem 'rack'
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012, Stefan Radomski & Rebecca Dietrich
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the libzero nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL Stefan Radomski or Rebecca Dietrich BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ zero-fix18
2
+ ==========
3
+
4
+ Fixes for run zero with Ruby 1.8
data/Thorfile ADDED
@@ -0,0 +1,6 @@
1
+ class Default < Thor
2
+ desc 'spec', 'run all specs'
3
+ def spec
4
+ exec 'rspec'
5
+ end
6
+ end
@@ -0,0 +1,74 @@
1
+ module URI
2
+
3
+ # Own implementation of decode_www_form.
4
+ # Shall behave almost like the original method, but without any encoding
5
+ # stuff.
6
+ #
7
+ # @param [String] query The query string
8
+ # @param [String] _encoding Unused, only for compatibility
9
+ # @return [Array] Parsed query
10
+ #
11
+ def self.decode_www_form(query, _encoding = nil)
12
+ return [] if query.empty?
13
+
14
+ unless query.match /^[^#=;&]*=[^#=;&]*([;&][^#=;&]*=[^#=;&]*)*$/
15
+ raise ArgumentError,
16
+ "invalid data of application/x-www-form-urlencoded (#{query})"
17
+ end
18
+ parsed = []
19
+ # breakes the string at & and ;
20
+ query.split(/[&;]/).each do |query_part|
21
+ # breakes the string parts at =
22
+ key, value = query_part.split('=')
23
+
24
+ # make an empty string out of value, if it's nil
25
+ value = '' if value.nil?
26
+ # append the key value pair on the result array
27
+ parsed << [
28
+ decode_www_form_component(key),
29
+ decode_www_form_component(value)
30
+ ]
31
+ end
32
+ # return result array
33
+ return parsed
34
+ end
35
+
36
+ TBLDECWWWCOMP_ = {}
37
+
38
+ # Own implementation of decode_www_form_component.
39
+ # Shall behave almost like the original method, but without any encoding
40
+ # stuff.
41
+ #
42
+ # @param [String] string
43
+ # @param [String] _encoding Unused, only for compatibility
44
+ # @return [String]
45
+ #
46
+ def self.decode_www_form_component(string, _encoding = nil)
47
+ # Fill table for URI special chars
48
+ if TBLDECWWWCOMP_.empty?
49
+ tbl = {}
50
+ 256.times do |i|
51
+ h, l = i>>4, i&15
52
+ tbl['%%%X%X' % [h, l]] = i.chr
53
+ tbl['%%%x%X' % [h, l]] = i.chr
54
+ tbl['%%%X%x' % [h, l]] = i.chr
55
+ tbl['%%%x%x' % [h, l]] = i.chr
56
+ end
57
+ tbl['+'] = ' '
58
+ begin
59
+ TBLDECWWWCOMP_.replace(tbl)
60
+ TBLDECWWWCOMP_.freeze
61
+ rescue
62
+ end
63
+ end
64
+ # unless /\A[^%]*(?:%\h\h[^%]*)*\z/ =~ str
65
+ # raise ArgumentError, "invalid %-encoding (#{str})"
66
+ # end
67
+
68
+ # Replace URI special chars
69
+ string.gsub(/\+|%[a-zA-Z0-9]{2}/) do |sub_string|
70
+ TBLDECWWWCOMP_[sub_string]
71
+ end
72
+ end
73
+
74
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module ZeroFix18
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/zero_fix18.rb ADDED
@@ -0,0 +1,6 @@
1
+ # Only add patches, if Ruby version is below 1.9, to prevent breaking things
2
+ if RUBY_VERSION <= '1.9'
3
+
4
+ require 'patches/uri'
5
+
6
+ end
@@ -0,0 +1,2 @@
1
+ require 'uri'
2
+ require 'zero_fix18'
@@ -0,0 +1,145 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe URI, '#decode_www_form' do
6
+
7
+ it 'seperates parameter into an array' do
8
+ result = URI::decode_www_form("foo=bar&bar=foo")
9
+
10
+ result.should eq([['foo', 'bar'], ['bar', 'foo']])
11
+ end
12
+
13
+ it 'can handle more than two equal parameter names' do
14
+ result = URI::decode_www_form("foo=bar1&foo=bar2")
15
+
16
+ result.should eq([['foo', 'bar1'], ['foo', 'bar2']])
17
+ end
18
+
19
+ it 'can handle whitespaces in query string' do
20
+ result = URI::decode_www_form("foo=bar&bar=bar%20foo")
21
+
22
+ result.should eq([['foo', 'bar'], ['bar', 'bar foo']])
23
+ end
24
+
25
+ it 'accepts semi-colons as seperators' do
26
+ result = URI::decode_www_form("foo=bar;bar=foo")
27
+
28
+ result.should eq([['foo', 'bar'], ['bar', 'foo']])
29
+ end
30
+
31
+ it 'seperates & and ; mixed queries properly' do
32
+ result = URI::decode_www_form("foo=bar&bar=foo;baz=foo")
33
+
34
+ result.should eq([['foo', 'bar'], ['bar', 'foo'], ['baz', 'foo']])
35
+ end
36
+
37
+ it 'does not accept only a normal string as query string' do
38
+ expect{
39
+ result = URI::decode_www_form("foo")
40
+
41
+ # does not work, probably should?
42
+ #result.should eq([['foo', '']])
43
+ }.to raise_error(
44
+ ArgumentError,
45
+ "invalid data of application/x-www-form-urlencoded (foo)"
46
+ )
47
+ end
48
+
49
+ it 'accepts empty values' do
50
+ result = URI::decode_www_form("foo=bar&bar=&baz=foo")
51
+
52
+ result.should eq([['foo', 'bar'], ['bar', ''], ['baz', 'foo']])
53
+ end
54
+
55
+ it 'understands plus as whitespace' do
56
+ result = URI::decode_www_form("foo=bar&bar=bar+foo")
57
+
58
+ result.should eq([['foo', 'bar'], ['bar', 'bar foo']])
59
+ end
60
+
61
+ it 'does not accept whitespaces in query string' do
62
+ result = URI::decode_www_form("foo=bar&bar=bar foo&baz=foo")
63
+
64
+ # Works, it probably shouldn't?
65
+ result.should eq([['foo', 'bar'], ['bar', 'bar foo'], ['baz', 'foo']])
66
+ end
67
+
68
+ it 'can handle non ascii letters in query string' do
69
+ result = URI::decode_www_form("foo=bär&bar=föö")
70
+
71
+ # Works, but it maybe shouldn't?
72
+ result.should eq([['foo', 'bär'], ['bar', 'föö']])
73
+ end
74
+
75
+ it 'can handle escaped non ascii letters in query string' do
76
+ result = URI::decode_www_form("foo=b%C3%A4r&bar=f%C3%B6%C3%B6")
77
+
78
+ result.should eq([['foo', 'bär'], ['bar', 'föö']])
79
+ end
80
+
81
+ it 'accepts - in query string' do
82
+ result = URI::decode_www_form("foo-bar=bar&bar=foo-bar")
83
+
84
+ result.should eq([['foo-bar', 'bar'], ['bar', 'foo-bar']])
85
+ end
86
+
87
+ it 'accepts . in query string' do
88
+ result = URI::decode_www_form("foo.bar=bar&bar=foo.bar")
89
+
90
+ result.should eq([['foo.bar', 'bar'], ['bar', 'foo.bar']])
91
+ end
92
+
93
+ it 'accepts ~ in query string' do
94
+ result = URI::decode_www_form("foo~bar=bar&bar=foo~bar")
95
+
96
+ result.should eq([['foo~bar', 'bar'], ['bar', 'foo~bar']])
97
+ end
98
+
99
+ it 'accepts _ in query string' do
100
+ result = URI::decode_www_form("foo_bar=bar&bar=foo_bar")
101
+
102
+ result.should eq([['foo_bar', 'bar'], ['bar', 'foo_bar']])
103
+ end
104
+
105
+ it 'handles [ ] in query string' do
106
+ result = URI::decode_www_form("foo[]=foo&foo[]=bar")
107
+
108
+ result.should eq([['foo[]', 'foo'], ['foo[]', 'bar']])
109
+ end
110
+
111
+ it 'returns an empty array, if query string is empty' do
112
+ result = URI::decode_www_form("")
113
+
114
+ result.should eq([])
115
+ end
116
+
117
+ it 'throws an error, if more than one = without an & or ; in between' do
118
+ expect {
119
+ result = URI::decode_www_form("foo=bar=foo&bar=foo=bar")
120
+ }.to raise_error(
121
+ ArgumentError,
122
+ "invalid data of application/x-www-form-urlencoded "+
123
+ "(foo=bar=foo&bar=foo=bar)"
124
+ )
125
+ end
126
+
127
+ it 'throws an error, if more than one & without an = in between' do
128
+ expect {
129
+ result = URI::decode_www_form("foo&bar=foo&bar")
130
+ }.to raise_error(
131
+ ArgumentError,
132
+ "invalid data of application/x-www-form-urlencoded (foo&bar=foo&bar)"
133
+ )
134
+ end
135
+
136
+ it 'throws an error, if more than one ; without an = in between' do
137
+ expect {
138
+ result = URI::decode_www_form("foo;bar=foo;bar")
139
+ }.to raise_error(
140
+ ArgumentError,
141
+ "invalid data of application/x-www-form-urlencoded (foo;bar=foo;bar)"
142
+ )
143
+ end
144
+
145
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'zero-fix18'
6
+ s.version = ZeroFix18::VERSION.dup
7
+
8
+ s.authors = ['Gibheer', 'Stormwind']
9
+ s.email = 'gibheer@gmail.com'
10
+ s.license = '3-clause BSD'
11
+ s.summary = 'Ruby 1.8 fixes for zero'
12
+ s.description = 'This little gem shall it make possible to run zero with ruby 1.8.'
13
+ s.homepage = 'http://github.com/libzero/zero-fix18'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = %w(lib)
18
+ s.extra_rdoc_files = %w(README.md)
19
+
20
+ s.rubygems_version = '1.8.24'
21
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zero-fix18
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gibheer
9
+ - Stormwind
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-12-23 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: This little gem shall it make possible to run zero with ruby 1.8.
16
+ email: gibheer@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
22
+ - !binary |-
23
+ LnJzcGVj
24
+ - !binary |-
25
+ LnRyYXZpcy55bWw=
26
+ - !binary |-
27
+ R2VtZmlsZQ==
28
+ - !binary |-
29
+ TElDRU5TRQ==
30
+ - !binary |-
31
+ UkVBRE1FLm1k
32
+ - !binary |-
33
+ VGhvcmZpbGU=
34
+ - !binary |-
35
+ bGliL3BhdGNoZXMvdXJpLnJi
36
+ - !binary |-
37
+ bGliL3ZlcnNpb24ucmI=
38
+ - !binary |-
39
+ bGliL3plcm9fZml4MTgucmI=
40
+ - !binary |-
41
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
42
+ - !binary |-
43
+ c3BlYy91cmkvZGVjb2RlX3d3d19mb3JtX3NwZWMucmI=
44
+ - !binary |-
45
+ emVyby1maXgxOC5nZW1zcGVj
46
+ homepage: http://github.com/libzero/zero-fix18
47
+ licenses:
48
+ - 3-clause BSD
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ none: false
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ none: false
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Ruby 1.8 fixes for zero
71
+ test_files:
72
+ - !binary |-
73
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
74
+ - !binary |-
75
+ c3BlYy91cmkvZGVjb2RlX3d3d19mb3JtX3NwZWMucmI=
76
+ has_rdoc: