ruby-uriparser 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3680a4b234ef77f02e5369d22a23279c068cc20d
4
- data.tar.gz: bb7396a7b8e6722707ab1e1b2eaca53cf3792e62
3
+ metadata.gz: 245f54ec2e764c1ab69698c09b42e171e8f9aa2b
4
+ data.tar.gz: ed8b45378e1ffbed1f411c3e3a94d877b80d97ab
5
5
  SHA512:
6
- metadata.gz: dbaa748e0db6df1c3d0c17c8dd7c1324ddee2b597731103dad64ee437d3d43d36da727e0341443267e46174e5bbfa04dbe9e7157db137e672aa610ef2671fb2a
7
- data.tar.gz: 4d49444f58aa5da71b1c3ab80c38504bc0aae7eb62a946c6ca0c7a77638faa6cbfa050f3e7c1f2b67d79fc1bb311c7335d2bac1bee7cb38fa812d2dc6db94623
6
+ metadata.gz: 7358c5f250a0f90388b1ef18b97cce995eda263efd3b32f6c283a3f4465ff9c403dcaa8068fbae01f8513514e29eb919f51e04893e3dec79a6f1be24b23855aa
7
+ data.tar.gz: a40e3e7c64b41435c04b87d69b9c6bfae6bbeaa3c2b95b6e940e0104b4f6f9fc8cc9695f0aeb26404a57683a55020aca3dd753e88291a85baa002cc4660a680c
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ruby-uriparser
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ruby-uriparser.png)](http://badge.fury.io/rb/ruby-uriparser)
4
+
3
5
  Ruby-uriparser is a wrapper for [uriparser](http://uriparser.sourceforge.net/) C library which is fast (linear input length time complexity), approximatelly 7.5x faster than the standard ruby URI library with a low memory consumption.
4
6
 
5
7
  It is a fairly reasonable hypothesis to consider that __all__ Ruby Rack applications will call, at least once, the `URI.parse` method for each http request, so this simple optimization can bring a significant impact on a high load environment. (See Benchmark)
@@ -17,16 +19,18 @@ If you want to override the URI class just include the following line in your co
17
19
 
18
20
  ## Benchmark
19
21
 
20
- The following numbers were computed for 10,000 `URI.parse` calls using the ruby benchmark library in a Mac OS X (10.8.5)/ 2.9Ghz Intel Core I5/ 8GB 1600 MHz DDR3 machine:
22
+ The following numbers were computed for 100,000 `URI.parse` calls using the ruby benchmark library in a Mac OS X (10.8.5)/ 2.9Ghz Intel Core I5/ 8GB 1600 MHz DDR3 machine:
21
23
 
22
- Rehearsal ----------------------------------------------
23
- URI 0.080000 0.000000 0.080000 ( 0.075157)
24
- UriParser 0.010000 0.000000 0.010000 ( 0.009013)
25
- ------------------------------------- total: 0.090000sec
24
+ Rehearsal ------------------------------------------------
25
+ URI 0.750000 0.000000 0.750000 ( 0.750619)
26
+ UriParser 0.110000 0.010000 0.120000 ( 0.111885)
27
+ Addressable 1.880000 0.000000 1.880000 ( 1.886091)
28
+ --------------------------------------- total: 2.750000sec
26
29
 
27
- user system total real
28
- URI 0.070000 0.000000 0.070000 ( 0.073731)
29
- UriParser 0.000000 0.000000 0.000000 ( 0.006310)
30
+ user system total real
31
+ URI 0.730000 0.000000 0.730000 ( 0.728169)
32
+ UriParser 0.110000 0.000000 0.110000 ( 0.107235)
33
+ Addressable 1.870000 0.000000 1.870000 ( 1.863334)
30
34
 
31
35
  ## Installation
32
36
 
data/Rakefile CHANGED
@@ -1,3 +1,18 @@
1
1
  require 'rake/extensiontask'
2
+ require 'rake/testtask'
2
3
 
3
- Rake::ExtensionTask.new('uriparser_ext')
4
+ Rake::ExtensionTask.new('uriparser_ext')
5
+
6
+ desc 'run tests'
7
+ Rake::TestTask.new(:test => :'ext:build') do |test|
8
+ test.libs << 'test'
9
+ test.pattern = 'test/**/*_test.rb'
10
+ test.verbose = true
11
+ end
12
+
13
+ namespace :ext do
14
+ desc 'build extention'
15
+ task :build => [:clobber, :compile]
16
+ end
17
+
18
+ task :default => :test
@@ -2,46 +2,58 @@
2
2
  #include <ruby.h>
3
3
  #include <uriparser/Uri.h>
4
4
 
5
+ #define FALSE 0
6
+ #define TRUE 1
7
+ typedef char bool;
8
+
5
9
  #define URI_TEXT_RANGE(uri_ptr, uri_field) ((uri_ptr->uri_field.afterLast == uri_ptr->uri_field.first) ? Qnil : \
6
10
  rb_str_new(uri_ptr->uri_field.first, uri_ptr->uri_field.afterLast - uri_ptr->uri_field.first))
7
11
 
8
- #define RB_URIPARSER_ATTR_READER(attribute, original) \
9
- static VALUE \
10
- rb_uriparser_get_##attribute(VALUE self) \
11
- { \
12
- struct uri_data *data; \
13
- \
14
- /* lazy load */ \
15
- Data_Get_Struct(self, struct uri_data, data); \
16
- if(RB_TYPE_P(data->attribute, T_UNDEF)) { \
17
- if(data->uri) { \
18
- data->attribute = URI_TEXT_RANGE(data->uri, original); \
19
- } else { \
20
- data->attribute = Qnil; \
21
- } \
22
- } \
23
- \
24
- return data->attribute; \
12
+ #define RB_URIPARSER_ATTR_READER(attribute, original) \
13
+ static VALUE \
14
+ rb_uriparser_get_##attribute(VALUE self) \
15
+ { \
16
+ struct uri_data *data; \
17
+ \
18
+ /* lazy load */ \
19
+ Data_Get_Struct(self, struct uri_data, data); \
20
+ if(RB_TYPE_P(data->attribute, T_UNDEF)) { \
21
+ if(data->uri) { \
22
+ data->attribute = URI_TEXT_RANGE(data->uri, original); \
23
+ } else { \
24
+ data->attribute = Qnil; \
25
+ } \
26
+ } \
27
+ \
28
+ return data->attribute; \
25
29
  }
26
30
 
27
- #define RB_URIPARSER_ATTR_WRITER(attribute) \
28
- static VALUE \
29
- rb_uriparser_set_##attribute(VALUE self, VALUE attribute) \
30
- { \
31
- VALUE old; \
32
- struct uri_data *data; \
33
- \
34
- Data_Get_Struct(self, struct uri_data, data); \
35
- old = data->attribute; \
36
- data->attribute = StringValue(attribute); \
37
- rb_gc_mark(old); \
38
- return data->attribute; \
31
+ #define RB_URIPARSER_ATTR_WRITER(attribute) \
32
+ static VALUE \
33
+ rb_uriparser_set_##attribute(VALUE self, VALUE attribute) \
34
+ { \
35
+ VALUE old; \
36
+ struct uri_data *data; \
37
+ \
38
+ Data_Get_Struct(self, struct uri_data, data); \
39
+ old = data->attribute; \
40
+ if(NIL_P(attribute)) { \
41
+ data->attribute = Qnil; \
42
+ } else { \
43
+ data->attribute = StringValue(attribute); \
44
+ } \
45
+ data->updated = TRUE; \
46
+ rb_gc_mark(old); \
47
+ \
48
+ return data->attribute; \
39
49
  }
40
50
 
41
- #define RB_URIPARSER_ATTR_ACCESSOR(attribute, original) \
42
- RB_URIPARSER_ATTR_READER(attribute, original); \
51
+ #define RB_URIPARSER_ATTR_ACCESSOR(attribute, original) \
52
+ RB_URIPARSER_ATTR_READER(attribute, original); \
43
53
  RB_URIPARSER_ATTR_WRITER(attribute);
44
54
 
55
+ #define VALID_TYPE(v) (!(NIL_P(v) || RB_TYPE_P(v, T_UNDEF)))
56
+
45
57
  /* Parser structure reused across requests */
46
58
  static UriParserStateA uri_parse_state;
47
59
  static VALUE rb_mUriParser;
@@ -49,34 +61,30 @@ static VALUE rb_cUri_Class;
49
61
 
50
62
  struct uri_data {
51
63
  UriUriA *uri; /* Parsed URI data */
64
+ bool updated; /* flag if any field was updated */
52
65
  VALUE scheme;
53
66
  VALUE userinfo;
54
- VALUE password;
55
67
  VALUE host;
56
68
  VALUE str_port;
57
69
  VALUE path;
58
70
  VALUE query;
59
- VALUE opaque;
60
- VALUE registry;
61
71
  VALUE fragment;
62
72
  };
63
73
 
74
+ /* Helper methods prototypes */
75
+ static void reset_fields(struct uri_data *);
76
+ static void populate_fields(VALUE uri);
77
+ static VALUE compose_uri_from_data(struct uri_data *);
78
+ static int parse_uri(char *, UriUriA *);
79
+ static void free_uri(UriUriA *);
80
+
64
81
  static void
65
82
  rb_uriparser_mark(void *p)
66
83
  {
67
84
  struct uri_data *ptr = p;
68
85
 
69
86
  if (ptr) {
70
- rb_gc_mark(ptr->scheme);
71
- rb_gc_mark(ptr->userinfo);
72
- rb_gc_mark(ptr->password);
73
- rb_gc_mark(ptr->host);
74
- rb_gc_mark(ptr->str_port);
75
- rb_gc_mark(ptr->path);
76
- rb_gc_mark(ptr->query);
77
- rb_gc_mark(ptr->opaque);
78
- rb_gc_mark(ptr->registry);
79
- rb_gc_mark(ptr->fragment);
87
+ reset_fields(ptr);
80
88
  }
81
89
  }
82
90
 
@@ -86,8 +94,7 @@ rb_uriparser_free(void *p)
86
94
  struct uri_data *ptr = p;
87
95
 
88
96
  if(ptr) {
89
- uriFreeUriMembersA(ptr->uri);
90
- xfree(ptr->uri);
97
+ free_uri(ptr->uri);
91
98
  xfree(ptr);
92
99
  }
93
100
  }
@@ -99,18 +106,16 @@ rb_uriparser_s_allocate(VALUE klass)
99
106
 
100
107
  if(data) {
101
108
  data->uri = NULL;
109
+ data->updated = FALSE;
102
110
  data->scheme = Qundef;
103
111
  data->userinfo = Qundef;
104
- data->password = Qundef;
105
112
  data->host = Qundef;
106
113
  data->str_port = Qundef;
107
114
  data->path = Qundef;
108
115
  data->query = Qundef;
109
- data->opaque = Qundef;
110
- data->registry = Qundef;
111
116
  data->fragment = Qundef;
112
117
  } else {
113
- rb_raise(rb_eRuntimeError, "unable to create UriParser::Generic class");
118
+ rb_raise(rb_eRuntimeError, "unable to create UriParser::URI class");
114
119
  }
115
120
 
116
121
  return Data_Wrap_Struct(klass, rb_uriparser_mark, rb_uriparser_free, data);
@@ -119,7 +124,7 @@ rb_uriparser_s_allocate(VALUE klass)
119
124
  static VALUE
120
125
  rb_uriparser_s_parse(VALUE klass, VALUE uri_obj)
121
126
  {
122
- char *uri_str = StringValueCStr(uri_obj);
127
+ char *str_uri = StringValueCStr(uri_obj);
123
128
  UriUriA *uri = ALLOC(UriUriA);
124
129
  struct uri_data *data;
125
130
  VALUE generic_uri;
@@ -128,11 +133,11 @@ rb_uriparser_s_parse(VALUE klass, VALUE uri_obj)
128
133
  Data_Get_Struct(generic_uri, struct uri_data, data);
129
134
 
130
135
  data->uri = uri;
131
- uri_parse_state.uri = uri;
132
- if(uriParseUriA(&uri_parse_state, uri_str) != URI_SUCCESS) {
133
- rb_raise(rb_eStandardError, "unable to parse the URI");
134
- }
135
136
 
137
+ if(parse_uri(str_uri, uri) != URI_SUCCESS) {
138
+ rb_raise(rb_eStandardError, "unable to parse the URI: %s", str_uri);
139
+ }
140
+
136
141
  return generic_uri;
137
142
  }
138
143
 
@@ -185,6 +190,150 @@ rb_uriparser_get_path(VALUE self)
185
190
  return data->path;
186
191
  }
187
192
 
193
+ /* TODO: Include option mask */
194
+ static VALUE
195
+ rb_uriparser_normalize_bang(VALUE self)
196
+ {
197
+ struct uri_data *data;
198
+
199
+ Data_Get_Struct(self, struct uri_data, data);
200
+ if(!data->uri || data->updated) {
201
+ if(data->updated) {
202
+ populate_fields(self);
203
+ }
204
+ /* Compute and parse the new URI */
205
+ VALUE new_uri = compose_uri_from_data(data);
206
+ UriUriA *uri = ALLOC(UriUriA);
207
+
208
+ if(parse_uri(StringValueCStr(new_uri), uri) != URI_SUCCESS) {
209
+ free_uri(uri);
210
+ rb_gc_mark(new_uri);
211
+ rb_raise(rb_eStandardError, "invalid URI (%s) to normalize", StringValueCStr(new_uri));
212
+ }
213
+
214
+ free_uri(data->uri);
215
+ rb_gc_mark(new_uri);
216
+ data->uri = uri;
217
+ }
218
+
219
+ if(uriNormalizeSyntaxA(data->uri) != URI_SUCCESS) {
220
+ rb_raise(rb_eStandardError, "unable to normalize the URI");
221
+ }
222
+ /* Invalidate any previous field value */
223
+ reset_fields(data);
224
+
225
+ return self;
226
+ }
227
+
228
+ static VALUE
229
+ rb_uriparser_escape(VALUE self)
230
+ {
231
+ return Qnil;
232
+ }
233
+
234
+ static VALUE
235
+ rb_uriparser_unescape(VALUE self)
236
+ {
237
+ return Qnil;
238
+ }
239
+
240
+ static void
241
+ reset_fields(struct uri_data *data)
242
+ {
243
+ data->updated = FALSE;
244
+
245
+ rb_gc_mark(data->scheme);
246
+ data->scheme = Qundef;
247
+
248
+ rb_gc_mark(data->userinfo);
249
+ data->userinfo = Qundef;
250
+
251
+ rb_gc_mark(data->host);
252
+ data->host = Qundef;
253
+
254
+ rb_gc_mark(data->str_port);
255
+ data->str_port = Qundef;
256
+
257
+ rb_gc_mark(data->path);
258
+ data->path = Qundef;
259
+
260
+ rb_gc_mark(data->query);
261
+ data->query = Qundef;
262
+
263
+ rb_gc_mark(data->fragment);
264
+ data->fragment = Qundef;
265
+ }
266
+
267
+ static void
268
+ populate_fields(VALUE uri)
269
+ {
270
+ rb_uriparser_get_scheme(uri);
271
+ rb_uriparser_get_userinfo(uri);
272
+ rb_uriparser_get_host(uri);
273
+ rb_uriparser_get_str_port(uri);
274
+ rb_uriparser_get_path(uri);
275
+ rb_uriparser_get_query(uri);
276
+ rb_uriparser_get_fragment(uri);
277
+ }
278
+
279
+ static VALUE
280
+ compose_uri_from_data(struct uri_data *data)
281
+ {
282
+ VALUE str_uri = rb_str_new2("");
283
+
284
+ if(VALID_TYPE(data->scheme)) {
285
+ rb_str_cat2(str_uri, StringValueCStr(data->scheme));
286
+ rb_str_cat2(str_uri, "://");
287
+ }
288
+
289
+ if(VALID_TYPE(data->userinfo)) {
290
+ rb_str_cat2(str_uri, StringValueCStr(data->userinfo));
291
+ rb_str_cat2(str_uri, "@");
292
+ }
293
+
294
+ if(VALID_TYPE(data->host)) {
295
+ rb_str_cat2(str_uri, StringValueCStr(data->host));
296
+ }
297
+
298
+ if(VALID_TYPE(data->str_port)) {
299
+ rb_str_cat2(str_uri, ":");
300
+ rb_str_cat2(str_uri, StringValueCStr(data->str_port));
301
+ }
302
+
303
+ if(VALID_TYPE(data->path)) {
304
+ rb_str_cat2(str_uri, StringValueCStr(data->path));
305
+ }
306
+
307
+ if(VALID_TYPE(data->query)) {
308
+ rb_str_cat2(str_uri, "?");
309
+ rb_str_cat2(str_uri, StringValueCStr(data->query));
310
+ }
311
+
312
+ if(VALID_TYPE(data->fragment)) {
313
+ rb_str_cat2(str_uri, "#");
314
+ rb_str_cat2(str_uri, StringValueCStr(data->fragment));
315
+ }
316
+
317
+ return str_uri;
318
+ }
319
+
320
+ static int
321
+ parse_uri(char *str_uri, UriUriA *uri)
322
+ {
323
+ uri_parse_state.uri = uri;
324
+
325
+ return uriParseUriA(&uri_parse_state, str_uri);
326
+ }
327
+
328
+ static void
329
+ free_uri(UriUriA *uri)
330
+ {
331
+ if(uri) {
332
+ uriFreeUriMembersA(uri);
333
+ xfree(uri);
334
+ }
335
+ }
336
+
188
337
  void
189
338
  Init_uriparser_ext()
190
339
  {
@@ -208,7 +357,9 @@ Init_uriparser_ext()
208
357
  rb_define_method(rb_cUri_Class, "fragment", rb_uriparser_get_fragment, 0);
209
358
  rb_define_method(rb_cUri_Class, "fragment=", rb_uriparser_set_fragment, 1);
210
359
 
211
- /* TODO: include opaque and registry methods */
360
+ rb_define_method(rb_cUri_Class, "normalize!", rb_uriparser_normalize_bang, 0);
361
+ rb_define_method(rb_cUri_Class, "escape", rb_uriparser_escape, 0);
362
+ rb_define_method(rb_cUri_Class, "unescape", rb_uriparser_unescape, 0);
212
363
 
213
364
  rb_define_singleton_method(rb_mUriParser, "parse", rb_uriparser_s_parse, 1);
214
365
  }
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.push File.expand_path(File.dirname(__FILE__))
1
2
  require 'uriparser_ext'
2
3
 
3
4
  module UriParser
@@ -11,16 +12,24 @@ module UriParser
11
12
  end
12
13
 
13
14
  def port=value
14
- @port = value.to_i
15
- str_port = value
15
+ @port = value.to_i
16
+ self.str_port = (value.nil? ? nil : value.to_s)
16
17
  end
17
18
 
18
19
  def user
19
- userinfo.split(':').first
20
+ if userinfo
21
+ userinfo.split(':').first
22
+ else
23
+ nil
24
+ end
20
25
  end
21
26
 
22
27
  def password
23
- userinfo.split(':')[1]
28
+ if userinfo
29
+ userinfo.split(':')[1]
30
+ else
31
+ nil
32
+ end
24
33
  end
25
34
  end
26
35
  end
@@ -1,3 +1,3 @@
1
1
  module UriParser
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+
4
+ require './lib/uriparser'
@@ -0,0 +1,119 @@
1
+ require 'test_helper'
2
+
3
+ class UriParserTest < Test::Unit::TestCase
4
+
5
+ context 'URI parsing' do
6
+ should 'raise an exception if was unable to parse the URI' do
7
+ assert_raise(StandardError) {UriParser.parse('invalid uri')}
8
+ end
9
+
10
+ should 'parse valid URI' do
11
+ uri = UriParser.parse('http://user:pwd@ruby-lang.org:80/en/about?yes=1#any')
12
+ assert_equal uri.scheme, 'http'
13
+ assert_equal uri.userinfo, 'user:pwd'
14
+ assert_equal uri.host, 'ruby-lang.org'
15
+ assert_equal uri.str_port, '80'
16
+ assert_equal uri.path, '/en/about'
17
+ assert_equal uri.query, 'yes=1'
18
+ assert_equal uri.fragment, 'any'
19
+ end
20
+
21
+ should 'paser valid but incomplete URI' do
22
+ uri = UriParser.parse('https://ruby-lang.org')
23
+ assert_equal uri.scheme, 'https'
24
+ assert_equal uri.userinfo, nil
25
+ assert_equal uri.host, 'ruby-lang.org'
26
+ assert_equal uri.str_port, nil
27
+ assert_equal uri.path, ''
28
+ assert_equal uri.query, nil
29
+ assert_equal uri.fragment, nil
30
+ end
31
+
32
+ should 'return URI object after a successful parsing' do
33
+ uri = UriParser.parse('https://ruby-lang.org')
34
+ assert_instance_of UriParser::URI, uri
35
+ end
36
+ end
37
+
38
+ context 'URI class API' do
39
+ should 'allow update any URI field' do
40
+ uri = UriParser.parse('http://user:pwd@ruby-lang.org:80/en/about?yes=1#any')
41
+ uri.scheme = 'ftp'
42
+ uri.userinfo = nil
43
+ uri.host = 'example.org'
44
+ uri.str_port = nil
45
+ uri.path = '/'
46
+ uri.query = 'xx=11'
47
+ uri.fragment = nil
48
+ assert_equal uri.scheme, 'ftp'
49
+ assert_equal uri.userinfo, nil
50
+ assert_equal uri.host, 'example.org'
51
+ assert_equal uri.str_port, nil
52
+ assert_equal uri.path, '/'
53
+ assert_equal uri.query, 'xx=11'
54
+ assert_equal uri.fragment, nil
55
+ end
56
+
57
+ should 'split userinfo data' do
58
+ uri = UriParser.parse('http://user:pwd@ruby-lang.org:80/en/about?yes=1#any')
59
+ assert_equal uri.user, 'user'
60
+ assert_equal uri.password, 'pwd'
61
+ end
62
+
63
+ should 'return nil if no user/password informed' do
64
+ uri = UriParser.parse('http://ruby-lang.org:80/en/about?yes=1#any')
65
+ assert_equal uri.user, nil
66
+ assert_equal uri.password, nil
67
+ end
68
+
69
+ should 'port and str_port be synchronized' do
70
+ uri = UriParser.parse('http://ruby-lang.org:80/en/about?yes=1#any')
71
+ uri.port = 1
72
+ assert_equal uri.str_port, '1'
73
+ end
74
+ end
75
+
76
+ context 'URI normalizing' do
77
+ should 'normalize a valid URI' do
78
+ uri = UriParser.parse('http://example.org/one/two/../../one')
79
+ uri.normalize!
80
+ assert_equal uri.scheme, 'http'
81
+ assert_equal uri.userinfo, nil
82
+ assert_equal uri.host, 'example.org'
83
+ assert_equal uri.str_port, nil
84
+ assert_equal uri.path, '/one'
85
+ assert_equal uri.query, nil
86
+ assert_equal uri.fragment, nil
87
+ end
88
+
89
+ should 'normalize an updated URI' do
90
+ uri = UriParser.parse('http://example.org')
91
+ uri.path = '/one/two/../../one'
92
+ assert_equal uri.path, '/one/two/../../one'
93
+ uri.normalize!
94
+ assert_equal uri.scheme, 'http'
95
+ assert_equal uri.userinfo, nil
96
+ assert_equal uri.host, 'example.org'
97
+ assert_equal uri.str_port, nil
98
+ assert_equal uri.path, '/one'
99
+ assert_equal uri.query, nil
100
+ assert_equal uri.fragment, nil
101
+ end
102
+
103
+ should 'normalize an URI manually created' do
104
+ uri = UriParser::URI.new
105
+ uri.scheme = 'http'
106
+ uri.host = 'example.org'
107
+ uri.path = '/one/two/../'
108
+ uri.fragment = 'test'
109
+ uri.normalize!
110
+ assert_equal uri.scheme, 'http'
111
+ assert_equal uri.userinfo, nil
112
+ assert_equal uri.host, 'example.org'
113
+ assert_equal uri.str_port, nil
114
+ assert_equal uri.path, '/one'
115
+ assert_equal uri.query, nil
116
+ assert_equal uri.fragment, 'test'
117
+ end
118
+ end
119
+ end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-uriparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Lewin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.5.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.5.0
13
33
  description: Ruby wrapper for uriparser C library
14
34
  email:
15
35
  - thiago_lewin@yahoo.com.br
@@ -18,24 +38,17 @@ extensions:
18
38
  - ext/uriparser_ext/extconf.rb
19
39
  extra_rdoc_files: []
20
40
  files:
21
- - benchmark/benchmark.rb
41
+ - Gemfile
42
+ - LICENSE
43
+ - README.md
44
+ - Rakefile
22
45
  - ext/uriparser_ext/extconf.rb
23
46
  - ext/uriparser_ext/uriparser.c
24
- - Gemfile
47
+ - lib/uriparser.rb
25
48
  - lib/uriparser/uri_gem.rb
26
49
  - lib/uriparser/version.rb
27
- - lib/uriparser.rb
28
- - lib/uriparser_ext.bundle
29
- - LICENSE
30
- - Rakefile
31
- - README.md
32
- - ruby-uriparser-0.1.0.gem
33
- - ruby-uriparser.gemspec
34
- - tmp/x86_64-darwin12.3.0/stage/lib/uriparser_ext.bundle
35
- - tmp/x86_64-darwin12.3.0/uriparser_ext/2.0.0/Makefile
36
- - tmp/x86_64-darwin12.3.0/uriparser_ext/2.0.0/mkmf.log
37
- - tmp/x86_64-darwin12.3.0/uriparser_ext/2.0.0/uriparser.o
38
- - tmp/x86_64-darwin12.3.0/uriparser_ext/2.0.0/uriparser_ext.bundle
50
+ - test/test_helper.rb
51
+ - test/uriparser_test.rb
39
52
  homepage: https://github.com/tlewin/ruby-uriparser
40
53
  licenses:
41
54
  - MIT
@@ -46,18 +59,20 @@ require_paths:
46
59
  - lib
47
60
  required_ruby_version: !ruby/object:Gem::Requirement
48
61
  requirements:
49
- - - '>='
62
+ - - ">="
50
63
  - !ruby/object:Gem::Version
51
64
  version: '0'
52
65
  required_rubygems_version: !ruby/object:Gem::Requirement
53
66
  requirements:
54
- - - '>='
67
+ - - ">="
55
68
  - !ruby/object:Gem::Version
56
69
  version: '0'
57
70
  requirements: []
58
71
  rubyforge_project:
59
- rubygems_version: 2.0.6
72
+ rubygems_version: 2.2.2
60
73
  signing_key:
61
74
  specification_version: 4
62
75
  summary: Ruby wrapper for uriparser C library
63
- test_files: []
76
+ test_files:
77
+ - test/test_helper.rb
78
+ - test/uriparser_test.rb
@@ -1,23 +0,0 @@
1
- require 'benchmark'
2
- require 'uri'
3
-
4
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
-
6
- require 'uriparser'
7
-
8
-
9
- n = ARGV[0] ? ARGV[0].to_i : 10_000
10
-
11
- Benchmark.bmbm(10) do |x|
12
- puts 'Complex URLs'
13
- x.report('URI') {n.times {URI.parse('https://www.ruby-lang.org/en/?a=1#test')}}
14
- x.report('UriParser') {n.times {UriParser.parse('https://www.ruby-lang.org/en/?a=1#test')}}
15
- end
16
-
17
- puts '#' * 20
18
-
19
- Benchmark.bmbm(10) do |x|
20
- puts 'Simple URLs'
21
- x.report('URI') {n.times {URI('https://www.ruby-lang.org/en/')}}
22
- x.report('UriParser') {n.times {UriParser.parse('https://www.ruby-lang.org/en/')}}
23
- end
Binary file
Binary file
@@ -1,17 +0,0 @@
1
- require './lib/uriparser/version'
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'ruby-uriparser'
5
- s.version = UriParser::VERSION
6
- s.date = Time.now
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ['Thiago Lewin']
9
- s.email = ['thiago_lewin@yahoo.com.br']
10
- s.homepage = 'https://github.com/tlewin/ruby-uriparser'
11
- s.summary = 'Ruby wrapper for uriparser C library'
12
- s.description = s.summary
13
- s.require_paths = ['lib']
14
- s.files = Dir['**/*'] - ['ruby-uriparser-0.0.1.gem']
15
- s.extensions = ["ext/uriparser_ext/extconf.rb"]
16
- s.license = 'MIT'
17
- end
@@ -1,238 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- # V=0 quiet, V=1 verbose. other values don't work.
5
- V = 0
6
- Q1 = $(V:1=)
7
- Q = $(Q1:0=@)
8
- ECHO1 = $(V:1=@:)
9
- ECHO = $(ECHO1:0=@echo)
10
-
11
- #### Start of system configuration section. ####
12
-
13
- srcdir = ../../../../ext/uriparser_ext
14
- topdir = /Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0
15
- hdrdir = $(topdir)
16
- arch_hdrdir = /Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-darwin12.3.0
17
- PATH_SEPARATOR = :
18
- VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
- prefix = /Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247
20
- rubysitearchprefix = $(rubylibprefix)/$(sitearch)
21
- rubyarchprefix = $(rubylibprefix)/$(arch)
22
- rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
23
- exec_prefix = $(prefix)
24
- vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
25
- sitearchhdrdir = $(sitehdrdir)/$(sitearch)
26
- rubyarchhdrdir = $(rubyhdrdir)/$(arch)
27
- vendorhdrdir = $(rubyhdrdir)/vendor_ruby
28
- sitehdrdir = $(rubyhdrdir)/site_ruby
29
- rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
30
- vendorarchdir = $(vendorlibdir)/$(sitearch)
31
- vendorlibdir = $(vendordir)/$(ruby_version)
32
- vendordir = $(rubylibprefix)/vendor_ruby
33
- sitearchdir = $(sitelibdir)/$(sitearch)
34
- sitelibdir = $(sitedir)/$(ruby_version)
35
- sitedir = $(rubylibprefix)/site_ruby
36
- rubyarchdir = $(rubylibdir)/$(arch)
37
- rubylibdir = $(rubylibprefix)/$(ruby_version)
38
- sitearchincludedir = $(includedir)/$(sitearch)
39
- archincludedir = $(includedir)/$(arch)
40
- sitearchlibdir = $(libdir)/$(sitearch)
41
- archlibdir = $(libdir)/$(arch)
42
- ridir = $(datarootdir)/$(RI_BASE_NAME)
43
- mandir = $(datarootdir)/man
44
- localedir = $(datarootdir)/locale
45
- libdir = $(exec_prefix)/lib
46
- psdir = $(docdir)
47
- pdfdir = $(docdir)
48
- dvidir = $(docdir)
49
- htmldir = $(docdir)
50
- infodir = $(datarootdir)/info
51
- docdir = $(datarootdir)/doc/$(PACKAGE)
52
- oldincludedir = /usr/include
53
- includedir = $(prefix)/include
54
- localstatedir = $(prefix)/var
55
- sharedstatedir = $(prefix)/com
56
- sysconfdir = $(DESTDIR)/etc
57
- datadir = $(datarootdir)
58
- datarootdir = $(prefix)/share
59
- libexecdir = $(exec_prefix)/libexec
60
- sbindir = $(exec_prefix)/sbin
61
- bindir = $(exec_prefix)/bin
62
- archdir = $(rubyarchdir)
63
-
64
-
65
- CC = /usr/bin/clang
66
- CXX = clang++
67
- LIBRUBY = $(LIBRUBY_A)
68
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
69
- LIBRUBYARG_SHARED =
70
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
71
- empty =
72
- OUTFLAG = -o $(empty)
73
- COUTFLAG = -o $(empty)
74
-
75
- RUBY_EXTCONF_H =
76
- cflags = $(optflags) $(debugflags) $(warnflags)
77
- optflags = -O3 -fno-fast-math
78
- debugflags = -ggdb3
79
- warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration
80
- CCDLFLAGS = -fno-common
81
- CFLAGS = $(CCDLFLAGS) -O3 -I/Users/mpapis/.sm/pkg/active/include -fPIC -pipe $(ARCH_FLAG)
82
- INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
83
- DEFS =
84
- CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
85
- CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
86
- ldflags = -L. -L/Users/mpapis/.sm/pkg/active/lib -L/usr/lib -fPIC -Bstatic -fstack-protector
87
- dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
88
- ARCH_FLAG = -arch x86_64
89
- DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
90
- LDSHARED = $(CC) -dynamic -bundle
91
- LDSHAREDXX = $(CXX) -dynamic -bundle
92
- AR = ar
93
- EXEEXT =
94
-
95
- RUBY_INSTALL_NAME = ruby
96
- RUBY_SO_NAME = ruby
97
- RUBYW_INSTALL_NAME =
98
- RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
99
- RUBYW_BASE_NAME = rubyw
100
- RUBY_BASE_NAME = ruby
101
-
102
- arch = x86_64-darwin12.3.0
103
- sitearch = $(arch)
104
- ruby_version = 2.0.0
105
- ruby = $(bindir)/ruby
106
- RUBY = $(ruby)
107
- ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
108
-
109
- RM = rm -f
110
- RM_RF = $(RUBY) -run -e rm -- -rf
111
- RMDIRS = rmdir -p
112
- MAKEDIRS = mkdir -p
113
- INSTALL = /usr/bin/install
114
- INSTALL_PROG = $(INSTALL) -m 0755
115
- INSTALL_DATA = $(INSTALL) -m 644
116
- COPY = cp
117
- TOUCH = exit >
118
-
119
- #### End of system configuration section. ####
120
-
121
- preload =
122
-
123
- libpath = . $(libdir)
124
- LIBPATH = -L. -L$(libdir)
125
- DEFFILE =
126
-
127
- CLEANFILES = mkmf.log
128
- DISTCLEANFILES =
129
- DISTCLEANDIRS =
130
-
131
- extout =
132
- extout_prefix =
133
- target_prefix =
134
- LOCAL_LIBS =
135
- LIBS = -luriparser -lpthread -ldl -lobjc
136
- ORIG_SRCS = uriparser.c
137
- SRCS = $(ORIG_SRCS)
138
- OBJS = uriparser.o
139
- HDRS =
140
- TARGET = uriparser_ext
141
- TARGET_NAME = uriparser_ext
142
- TARGET_ENTRY = Init_$(TARGET_NAME)
143
- DLLIB = $(TARGET).bundle
144
- EXTSTATIC =
145
- STATIC_LIB =
146
-
147
- BINDIR = $(DESTDIR)$(bindir)
148
- RUBYCOMMONDIR = $(DESTDIR)$(sitedir)$(target_prefix)
149
- RUBYLIBDIR = $(DESTDIR)$(sitelibdir)$(target_prefix)
150
- RUBYARCHDIR = $(DESTDIR)$(sitearchdir)$(target_prefix)
151
- HDRDIR = $(DESTDIR)$(rubyhdrdir)/ruby$(target_prefix)
152
- ARCHHDRDIR = $(DESTDIR)$(rubyhdrdir)/$(arch)/ruby$(target_prefix)
153
-
154
- TARGET_SO = $(DLLIB)
155
- CLEANLIBS = $(TARGET).bundle
156
- CLEANOBJS = *.o *.bak
157
-
158
- all: $(DLLIB)
159
- static: $(STATIC_LIB)
160
- .PHONY: all install static install-so install-rb
161
- .PHONY: clean clean-so clean-static clean-rb
162
-
163
- clean-static::
164
- clean-rb-default::
165
- clean-rb::
166
- clean-so::
167
- clean: clean-so clean-static clean-rb-default clean-rb
168
- -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
169
-
170
- distclean-rb-default::
171
- distclean-rb::
172
- distclean-so::
173
- distclean-static::
174
- distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
175
- -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
176
- -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
177
- -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
178
-
179
- realclean: distclean
180
- install: install-so install-rb
181
-
182
- install-so: $(DLLIB) ./.RUBYARCHDIR.time
183
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
184
- clean-static::
185
- -$(Q)$(RM) $(STATIC_LIB)
186
- install-rb: pre-install-rb install-rb-default
187
- install-rb-default: pre-install-rb-default
188
- pre-install-rb: Makefile
189
- pre-install-rb-default: Makefile
190
- pre-install-rb-default:
191
- $(ECHO) installing default uriparser_ext libraries
192
- ./.RUBYARCHDIR.time:
193
- $(Q) $(MAKEDIRS) $(RUBYARCHDIR)
194
- $(Q) $(TOUCH) $@
195
-
196
- site-install: site-install-so site-install-rb
197
- site-install-so: install-so
198
- site-install-rb: install-rb
199
-
200
- .SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
201
-
202
- .cc.o:
203
- $(ECHO) compiling $(<)
204
- $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
205
-
206
- .mm.o:
207
- $(ECHO) compiling $(<)
208
- $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
209
-
210
- .cxx.o:
211
- $(ECHO) compiling $(<)
212
- $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
213
-
214
- .cpp.o:
215
- $(ECHO) compiling $(<)
216
- $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
217
-
218
- .C.o:
219
- $(ECHO) compiling $(<)
220
- $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
221
-
222
- .c.o:
223
- $(ECHO) compiling $(<)
224
- $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
225
-
226
- .m.o:
227
- $(ECHO) compiling $(<)
228
- $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
229
-
230
- $(DLLIB): $(OBJS) Makefile
231
- $(ECHO) linking shared-object $(DLLIB)
232
- -$(Q)$(RM) $(@)
233
- $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
234
- $(Q) test -z '$(RUBY_CODESIGN)' || codesign -s '$(RUBY_CODESIGN)' -f $@
235
-
236
-
237
-
238
- $(OBJS): $(HDRS) $(ruby_headers)
@@ -1,61 +0,0 @@
1
- have_library: checking for main() in -luriparser... -------------------- yes
2
-
3
- "/usr/bin/clang -o conftest -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-darwin12.3.0 -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/backward -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0 -I../../../../ext/uriparser_ext -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/mpapis/.sm/pkg/active/include -fPIC -pipe conftest.c -L. -L/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/lib -L. -L/Users/mpapis/.sm/pkg/active/lib -L/usr/lib -fPIC -Bstatic -fstack-protector -arch x86_64 -lruby-static -lpthread -ldl -lobjc "
4
- ld: warning: directory not found for option '-L/Users/mpapis/.sm/pkg/active/lib'
5
- checked program was:
6
- /* begin */
7
- 1: #include "ruby.h"
8
- 2:
9
- 3: int main(int argc, char **argv)
10
- 4: {
11
- 5: return 0;
12
- 6: }
13
- /* end */
14
-
15
- "/usr/bin/clang -o conftest -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-darwin12.3.0 -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/backward -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0 -I../../../../ext/uriparser_ext -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/mpapis/.sm/pkg/active/include -fPIC -pipe conftest.c -L. -L/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/lib -L. -L/Users/mpapis/.sm/pkg/active/lib -L/usr/lib -fPIC -Bstatic -fstack-protector -arch x86_64 -lruby-static -luriparser -lpthread -ldl -lobjc "
16
- conftest.c:5:57: error: use of undeclared identifier 'main'
17
- int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
18
- ^
19
- 1 error generated.
20
- checked program was:
21
- /* begin */
22
- 1: #include "ruby.h"
23
- 2:
24
- 3: /*top*/
25
- 4: extern int t(void);
26
- 5: int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
27
- 6: int main(int argc, char **argv)
28
- 7: {
29
- 8: if (argc > 1000000) {
30
- 9: printf("%p", &t);
31
- 10: }
32
- 11:
33
- 12: return 0;
34
- 13: }
35
- /* end */
36
-
37
- "/usr/bin/clang -o conftest -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-darwin12.3.0 -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/backward -I/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0 -I../../../../ext/uriparser_ext -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/mpapis/.sm/pkg/active/include -fPIC -pipe conftest.c -L. -L/Users/thiagolewin/.rvm/rubies/ruby-2.0.0-p247/lib -L. -L/Users/mpapis/.sm/pkg/active/lib -L/usr/lib -fPIC -Bstatic -fstack-protector -arch x86_64 -lruby-static -luriparser -lpthread -ldl -lobjc "
38
- conftest.c:5:15: warning: implicit declaration of function 'main' is invalid in C99 [-Wimplicit-function-declaration]
39
- int t(void) { main(); return 0; }
40
- ^
41
- 1 warning generated.
42
- ld: warning: directory not found for option '-L/Users/mpapis/.sm/pkg/active/lib'
43
- checked program was:
44
- /* begin */
45
- 1: #include "ruby.h"
46
- 2:
47
- 3: /*top*/
48
- 4: extern int t(void);
49
- 5: int t(void) { main(); return 0; }
50
- 6: int main(int argc, char **argv)
51
- 7: {
52
- 8: if (argc > 1000000) {
53
- 9: printf("%p", &t);
54
- 10: }
55
- 11:
56
- 12: return 0;
57
- 13: }
58
- /* end */
59
-
60
- --------------------
61
-