escape_utils 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/MIT-LICENSE +1 -1
- data/ext/escape_utils/escape_utils.c +8 -84
- data/lib/escape_utils/version.rb +1 -1
- data/spec/html/escape_spec.rb +4 -11
- data/spec/html/unescape_spec.rb +4 -11
- data/spec/javascript/escape_spec.rb +4 -11
- data/spec/javascript/unescape_spec.rb +4 -11
- data/spec/query/escape_spec.rb +6 -15
- data/spec/query/unescape_spec.rb +6 -15
- data/spec/uri/escape_spec.rb +6 -15
- data/spec/uri/unescape_spec.rb +6 -15
- data/spec/url/escape_spec.rb +6 -15
- data/spec/url/unescape_spec.rb +6 -15
- metadata +6 -6
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
CHANGED
@@ -303,10 +303,6 @@ static VALUE rb_escape_html(int argc, VALUE * argv, VALUE self) {
|
|
303
303
|
VALUE str, rb_secure;
|
304
304
|
int secure = html_secure;
|
305
305
|
VALUE rb_output_buf;
|
306
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
307
|
-
rb_encoding *default_internal_enc;
|
308
|
-
rb_encoding *original_encoding;
|
309
|
-
#endif
|
310
306
|
unsigned char *inBuf, *outBuf;
|
311
307
|
size_t len, new_len;
|
312
308
|
|
@@ -318,10 +314,6 @@ static VALUE rb_escape_html(int argc, VALUE * argv, VALUE self) {
|
|
318
314
|
|
319
315
|
Check_Type(str, T_STRING);
|
320
316
|
|
321
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
322
|
-
default_internal_enc = rb_default_internal_encoding();
|
323
|
-
original_encoding = rb_enc_get(str);
|
324
|
-
#endif
|
325
317
|
inBuf = (unsigned char*)RSTRING_PTR(str);
|
326
318
|
len = RSTRING_LEN(str);
|
327
319
|
|
@@ -340,28 +332,17 @@ static VALUE rb_escape_html(int argc, VALUE * argv, VALUE self) {
|
|
340
332
|
rb_str_resize(rb_output_buf, new_len);
|
341
333
|
|
342
334
|
#ifdef HAVE_RUBY_ENCODING_H
|
343
|
-
|
344
|
-
if (default_internal_enc) {
|
345
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
346
|
-
}
|
335
|
+
rb_enc_copy(rb_output_buf, str);
|
347
336
|
#endif
|
348
337
|
return rb_output_buf;
|
349
338
|
}
|
350
339
|
|
351
340
|
static VALUE rb_unescape_html(VALUE self, VALUE str) {
|
352
341
|
VALUE rb_output_buf;
|
353
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
354
|
-
rb_encoding *default_internal_enc;
|
355
|
-
rb_encoding *original_encoding;
|
356
|
-
#endif
|
357
342
|
unsigned char *inBuf, *outBuf;
|
358
343
|
size_t len, new_len;
|
359
344
|
|
360
345
|
Check_Type(str, T_STRING);
|
361
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
362
|
-
default_internal_enc = rb_default_internal_encoding();
|
363
|
-
original_encoding = rb_enc_get(str);
|
364
|
-
#endif
|
365
346
|
inBuf = (unsigned char*)RSTRING_PTR(str);
|
366
347
|
len = RSTRING_LEN(str);
|
367
348
|
|
@@ -380,20 +361,13 @@ static VALUE rb_unescape_html(VALUE self, VALUE str) {
|
|
380
361
|
rb_str_resize(rb_output_buf, new_len);
|
381
362
|
|
382
363
|
#ifdef HAVE_RUBY_ENCODING_H
|
383
|
-
|
384
|
-
if (default_internal_enc) {
|
385
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
386
|
-
}
|
364
|
+
rb_enc_copy(rb_output_buf, str);
|
387
365
|
#endif
|
388
366
|
return rb_output_buf;
|
389
367
|
}
|
390
368
|
|
391
369
|
static VALUE rb_escape_javascript(VALUE self, VALUE str) {
|
392
370
|
VALUE rb_output_buf;
|
393
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
394
|
-
rb_encoding *default_internal_enc;
|
395
|
-
rb_encoding *original_encoding;
|
396
|
-
#endif
|
397
371
|
unsigned char *inBuf, *outBuf;
|
398
372
|
size_t len, new_len;
|
399
373
|
|
@@ -403,10 +377,6 @@ static VALUE rb_escape_javascript(VALUE self, VALUE str) {
|
|
403
377
|
|
404
378
|
Check_Type(str, T_STRING);
|
405
379
|
|
406
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
407
|
-
default_internal_enc = rb_default_internal_encoding();
|
408
|
-
original_encoding = rb_enc_get(str);
|
409
|
-
#endif
|
410
380
|
inBuf = (unsigned char*)RSTRING_PTR(str);
|
411
381
|
len = RSTRING_LEN(str);
|
412
382
|
|
@@ -425,20 +395,13 @@ static VALUE rb_escape_javascript(VALUE self, VALUE str) {
|
|
425
395
|
rb_str_resize(rb_output_buf, new_len);
|
426
396
|
|
427
397
|
#ifdef HAVE_RUBY_ENCODING_H
|
428
|
-
|
429
|
-
if (default_internal_enc) {
|
430
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
431
|
-
}
|
398
|
+
rb_enc_copy(rb_output_buf, str);
|
432
399
|
#endif
|
433
400
|
return rb_output_buf;
|
434
401
|
}
|
435
402
|
|
436
403
|
static VALUE rb_unescape_javascript(VALUE self, VALUE str) {
|
437
404
|
VALUE rb_output_buf;
|
438
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
439
|
-
rb_encoding *default_internal_enc;
|
440
|
-
rb_encoding *original_encoding;
|
441
|
-
#endif
|
442
405
|
unsigned char *inBuf, *outBuf;
|
443
406
|
size_t len, new_len;
|
444
407
|
|
@@ -448,10 +411,6 @@ static VALUE rb_unescape_javascript(VALUE self, VALUE str) {
|
|
448
411
|
|
449
412
|
Check_Type(str, T_STRING);
|
450
413
|
|
451
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
452
|
-
default_internal_enc = rb_default_internal_encoding();
|
453
|
-
original_encoding = rb_enc_get(str);
|
454
|
-
#endif
|
455
414
|
inBuf = (unsigned char*)RSTRING_PTR(str);
|
456
415
|
len = RSTRING_LEN(str);
|
457
416
|
|
@@ -470,29 +429,18 @@ static VALUE rb_unescape_javascript(VALUE self, VALUE str) {
|
|
470
429
|
rb_str_resize(rb_output_buf, new_len);
|
471
430
|
|
472
431
|
#ifdef HAVE_RUBY_ENCODING_H
|
473
|
-
|
474
|
-
if (default_internal_enc) {
|
475
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
476
|
-
}
|
432
|
+
rb_enc_copy(rb_output_buf, str);
|
477
433
|
#endif
|
478
434
|
return rb_output_buf;
|
479
435
|
}
|
480
436
|
|
481
437
|
static VALUE rb_escape_url(VALUE self, VALUE str) {
|
482
438
|
VALUE rb_output_buf;
|
483
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
484
|
-
rb_encoding *default_internal_enc;
|
485
|
-
rb_encoding *original_encoding;
|
486
|
-
#endif
|
487
439
|
unsigned char *inBuf, *outBuf;
|
488
440
|
size_t len, new_len;
|
489
441
|
|
490
442
|
Check_Type(str, T_STRING);
|
491
443
|
|
492
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
493
|
-
default_internal_enc = rb_default_internal_encoding();
|
494
|
-
original_encoding = rb_enc_get(str);
|
495
|
-
#endif
|
496
444
|
inBuf = (unsigned char*)RSTRING_PTR(str);
|
497
445
|
len = RSTRING_LEN(str);
|
498
446
|
|
@@ -511,10 +459,7 @@ static VALUE rb_escape_url(VALUE self, VALUE str) {
|
|
511
459
|
rb_str_resize(rb_output_buf, new_len);
|
512
460
|
|
513
461
|
#ifdef HAVE_RUBY_ENCODING_H
|
514
|
-
|
515
|
-
if (default_internal_enc) {
|
516
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
517
|
-
}
|
462
|
+
rb_enc_copy(rb_output_buf, str);
|
518
463
|
#endif
|
519
464
|
return rb_output_buf;
|
520
465
|
}
|
@@ -523,10 +468,6 @@ static VALUE rb_unescape_url(VALUE self, VALUE str) {
|
|
523
468
|
Check_Type(str, T_STRING);
|
524
469
|
|
525
470
|
VALUE rb_output_buf;
|
526
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
527
|
-
rb_encoding *default_internal_enc = rb_default_internal_encoding();
|
528
|
-
rb_encoding *original_encoding = rb_enc_get(str);
|
529
|
-
#endif
|
530
471
|
unsigned char *inBuf = (unsigned char*)RSTRING_PTR(str);
|
531
472
|
size_t len = RSTRING_LEN(str);
|
532
473
|
|
@@ -546,10 +487,7 @@ static VALUE rb_unescape_url(VALUE self, VALUE str) {
|
|
546
487
|
rb_str_resize(rb_output_buf, new_len);
|
547
488
|
|
548
489
|
#ifdef HAVE_RUBY_ENCODING_H
|
549
|
-
|
550
|
-
if (default_internal_enc) {
|
551
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
552
|
-
}
|
490
|
+
rb_enc_copy(rb_output_buf, str);
|
553
491
|
#endif
|
554
492
|
return rb_output_buf;
|
555
493
|
}
|
@@ -558,10 +496,6 @@ static VALUE rb_escape_uri(VALUE self, VALUE str) {
|
|
558
496
|
Check_Type(str, T_STRING);
|
559
497
|
|
560
498
|
VALUE rb_output_buf;
|
561
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
562
|
-
rb_encoding *default_internal_enc = rb_default_internal_encoding();
|
563
|
-
rb_encoding *original_encoding = rb_enc_get(str);
|
564
|
-
#endif
|
565
499
|
unsigned char *inBuf = (unsigned char*)RSTRING_PTR(str);
|
566
500
|
size_t len = RSTRING_LEN(str);
|
567
501
|
unsigned char *outBuf;
|
@@ -581,10 +515,7 @@ static VALUE rb_escape_uri(VALUE self, VALUE str) {
|
|
581
515
|
rb_str_resize(rb_output_buf, new_len);
|
582
516
|
|
583
517
|
#ifdef HAVE_RUBY_ENCODING_H
|
584
|
-
|
585
|
-
if (default_internal_enc) {
|
586
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
587
|
-
}
|
518
|
+
rb_enc_copy(rb_output_buf, str);
|
588
519
|
#endif
|
589
520
|
return rb_output_buf;
|
590
521
|
}
|
@@ -593,10 +524,6 @@ static VALUE rb_unescape_uri(VALUE self, VALUE str) {
|
|
593
524
|
Check_Type(str, T_STRING);
|
594
525
|
|
595
526
|
VALUE rb_output_buf;
|
596
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
597
|
-
rb_encoding *default_internal_enc = rb_default_internal_encoding();
|
598
|
-
rb_encoding *original_encoding = rb_enc_get(str);
|
599
|
-
#endif
|
600
527
|
unsigned char *inBuf = (unsigned char*)RSTRING_PTR(str);
|
601
528
|
size_t len = RSTRING_LEN(str);
|
602
529
|
unsigned char *outBuf;
|
@@ -616,10 +543,7 @@ static VALUE rb_unescape_uri(VALUE self, VALUE str) {
|
|
616
543
|
rb_str_resize(rb_output_buf, new_len);
|
617
544
|
|
618
545
|
#ifdef HAVE_RUBY_ENCODING_H
|
619
|
-
|
620
|
-
if (default_internal_enc) {
|
621
|
-
rb_output_buf = rb_str_export_to_enc(rb_output_buf, default_internal_enc);
|
622
|
-
}
|
546
|
+
rb_enc_copy(rb_output_buf, str);
|
623
547
|
#endif
|
624
548
|
return rb_output_buf;
|
625
549
|
}
|
data/lib/escape_utils/version.rb
CHANGED
data/spec/html/escape_spec.rb
CHANGED
@@ -33,18 +33,11 @@ describe EscapeUtils, "escape_html" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
if RUBY_VERSION =~ /^1.9/
|
36
|
-
it "should
|
37
|
-
|
38
|
-
str = "<b>Bourbon & Branch</b>"
|
39
|
-
str = str.encode('us-ascii')
|
36
|
+
it "return value should be in original string's encoding" do
|
37
|
+
str = "<b>Bourbon & Branch</b>".encode('us-ascii')
|
40
38
|
EscapeUtils.escape_html(str).encoding.should eql(Encoding.find('us-ascii'))
|
41
|
-
|
42
|
-
|
43
|
-
it "should use Encoding.default_internal" do
|
44
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
45
|
-
EscapeUtils.escape_html("<b>Bourbon & Branch</b>").encoding.should eql(Encoding.default_internal)
|
46
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
47
|
-
EscapeUtils.escape_html("<b>Bourbon & Branch</b>").encoding.should eql(Encoding.default_internal)
|
39
|
+
str = "<b>Bourbon & Branch</b>".encode('utf-8')
|
40
|
+
EscapeUtils.escape_html(str).encoding.should eql(Encoding.find('utf-8'))
|
48
41
|
end
|
49
42
|
end
|
50
43
|
end
|
data/spec/html/unescape_spec.rb
CHANGED
@@ -28,18 +28,11 @@ describe EscapeUtils, "unescape_html" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
if RUBY_VERSION =~ /^1.9/
|
31
|
-
it "should
|
32
|
-
|
33
|
-
str = "<b>Bourbon & Branch</b>"
|
34
|
-
str = str.encode('us-ascii')
|
31
|
+
it "return value should be in original string's encoding" do
|
32
|
+
str = "<b>Bourbon & Branch</b>".encode('us-ascii')
|
35
33
|
EscapeUtils.unescape_html(str).encoding.should eql(Encoding.find('us-ascii'))
|
36
|
-
|
37
|
-
|
38
|
-
it "should use Encoding.default_internal" do
|
39
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
40
|
-
EscapeUtils.unescape_html("<b>Bourbon & Branch</b>").encoding.should eql(Encoding.default_internal)
|
41
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
42
|
-
EscapeUtils.unescape_html("<b>Bourbon & Branch</b>").encoding.should eql(Encoding.default_internal)
|
34
|
+
str = "<b>Bourbon & Branch</b>".encode('utf-8')
|
35
|
+
EscapeUtils.unescape_html(str).encoding.should eql(Encoding.find('utf-8'))
|
43
36
|
end
|
44
37
|
end
|
45
38
|
end
|
@@ -24,18 +24,11 @@ describe EscapeUtils, "escape_javascript" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if RUBY_VERSION =~ /^1.9/
|
27
|
-
it "should
|
28
|
-
|
29
|
-
str = %(dont </close> tags)
|
30
|
-
str = str.encode('us-ascii')
|
27
|
+
it "return value should be in original string's encoding" do
|
28
|
+
str = "dont </close> tags".encode('us-ascii')
|
31
29
|
EscapeUtils.escape_javascript(str).encoding.should eql(Encoding.find('us-ascii'))
|
32
|
-
|
33
|
-
|
34
|
-
it "should use Encoding.default_internal" do
|
35
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
36
|
-
EscapeUtils.escape_javascript(%(dont </close> tags)).encoding.should eql(Encoding.default_internal)
|
37
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
38
|
-
EscapeUtils.escape_javascript(%(dont </close> tags)).encoding.should eql(Encoding.default_internal)
|
30
|
+
str = "dont </close> tags".encode('utf-8')
|
31
|
+
EscapeUtils.escape_javascript(str).encoding.should eql(Encoding.find('utf-8'))
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
@@ -28,18 +28,11 @@ describe EscapeUtils, "unescape_javascript" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
if RUBY_VERSION =~ /^1.9/
|
31
|
-
it "should
|
32
|
-
|
33
|
-
str = %(dont <\\/close> tags)
|
34
|
-
str = str.encode('us-ascii')
|
31
|
+
it "return value should be in original string's encoding" do
|
32
|
+
str = "dont <\\/close> tags".encode('us-ascii')
|
35
33
|
EscapeUtils.unescape_javascript(str).encoding.should eql(Encoding.find('us-ascii'))
|
36
|
-
|
37
|
-
|
38
|
-
it "should use Encoding.default_internal" do
|
39
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
40
|
-
EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).encoding.should eql(Encoding.default_internal)
|
41
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
42
|
-
EscapeUtils.unescape_javascript(%(dont <\\/close> tags)).encoding.should eql(Encoding.default_internal)
|
34
|
+
str = "dont <\\/close> tags".encode('utf-8')
|
35
|
+
EscapeUtils.unescape_javascript(str).encoding.should eql(Encoding.find('utf-8'))
|
43
36
|
end
|
44
37
|
end
|
45
38
|
end
|
data/spec/query/escape_spec.rb
CHANGED
@@ -28,27 +28,18 @@ describe EscapeUtils, "escape_url" do
|
|
28
28
|
|
29
29
|
# NOTE: from Rack's test suite
|
30
30
|
it "should escape correctly for multibyte characters" do
|
31
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
32
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
31
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
33
32
|
EscapeUtils.escape_url(matz_name).should eql('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8')
|
34
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
35
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
33
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
36
34
|
EscapeUtils.escape_url(matz_name_sep).should eql('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8')
|
37
35
|
end
|
38
36
|
|
39
37
|
if RUBY_VERSION =~ /^1.9/
|
40
|
-
it "should
|
41
|
-
|
42
|
-
str = "http://www.homerun.com/"
|
43
|
-
str = str.encode('us-ascii')
|
38
|
+
it "return value should be in original string's encoding" do
|
39
|
+
str = "http://www.homerun.com/".encode('us-ascii')
|
44
40
|
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
45
|
-
|
46
|
-
|
47
|
-
it "should use Encoding.default_internal" do
|
48
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
49
|
-
EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
50
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
51
|
-
EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
41
|
+
str = "http://www.homerun.com/".encode('utf-8')
|
42
|
+
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
52
43
|
end
|
53
44
|
end
|
54
45
|
end
|
data/spec/query/unescape_spec.rb
CHANGED
@@ -28,27 +28,18 @@ describe EscapeUtils, "unescape_url" do
|
|
28
28
|
|
29
29
|
# NOTE: from Rack's test suite
|
30
30
|
it "should unescape correctly for multibyte characters" do
|
31
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
32
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
31
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
33
32
|
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
|
34
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
35
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
33
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
36
34
|
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8').should eql(matz_name_sep)
|
37
35
|
end
|
38
36
|
|
39
37
|
if RUBY_VERSION =~ /^1.9/
|
40
|
-
it "should
|
41
|
-
|
42
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F"
|
43
|
-
str = str.encode('us-ascii')
|
38
|
+
it "return value should be in original string's encoding" do
|
39
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('us-ascii')
|
44
40
|
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
45
|
-
|
46
|
-
|
47
|
-
it "should use Encoding.default_internal" do
|
48
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
49
|
-
EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
50
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
51
|
-
EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
41
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('utf-8')
|
42
|
+
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
52
43
|
end
|
53
44
|
end
|
54
45
|
end
|
data/spec/uri/escape_spec.rb
CHANGED
@@ -27,27 +27,18 @@ describe EscapeUtils, "escape_uri" do
|
|
27
27
|
|
28
28
|
# NOTE: from Rack's test suite
|
29
29
|
it "should escape correctly for multibyte characters" do
|
30
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
31
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
30
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
32
31
|
EscapeUtils.escape_uri(matz_name).should eql('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8')
|
33
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
34
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
32
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
35
33
|
EscapeUtils.escape_uri(matz_name_sep).should eql('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8')
|
36
34
|
end
|
37
35
|
|
38
36
|
if RUBY_VERSION =~ /^1.9/
|
39
|
-
it "should
|
40
|
-
|
41
|
-
str = "http://www.homerun.com/"
|
42
|
-
str = str.encode('us-ascii')
|
37
|
+
it "return value should be in original string's encoding" do
|
38
|
+
str = "http://www.homerun.com/".encode('us-ascii')
|
43
39
|
EscapeUtils.escape_uri(str).encoding.should eql(Encoding.find('us-ascii'))
|
44
|
-
|
45
|
-
|
46
|
-
it "should use Encoding.default_internal" do
|
47
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
48
|
-
EscapeUtils.escape_uri("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
49
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
50
|
-
EscapeUtils.escape_uri("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
40
|
+
str = "http://www.homerun.com/".encode('utf-8')
|
41
|
+
EscapeUtils.escape_uri(str).encoding.should eql(Encoding.find('utf-8'))
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
data/spec/uri/unescape_spec.rb
CHANGED
@@ -39,27 +39,18 @@ describe EscapeUtils, "unescape_uri" do
|
|
39
39
|
|
40
40
|
# NOTE: from Rack's test suite
|
41
41
|
it "should unescape correctly for multibyte characters" do
|
42
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
43
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
42
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
44
43
|
EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
|
45
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
46
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
44
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
47
45
|
EscapeUtils.unescape_uri('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8').should eql(matz_name_sep)
|
48
46
|
end
|
49
47
|
|
50
48
|
if RUBY_VERSION =~ /^1.9/
|
51
|
-
it "should
|
52
|
-
|
53
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F"
|
54
|
-
str = str.encode('us-ascii')
|
49
|
+
it "return value should be in original string's encoding" do
|
50
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('us-ascii')
|
55
51
|
EscapeUtils.unescape_uri(str).encoding.should eql(Encoding.find('us-ascii'))
|
56
|
-
|
57
|
-
|
58
|
-
it "should use Encoding.default_internal" do
|
59
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
60
|
-
EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
61
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
62
|
-
EscapeUtils.unescape_uri("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
52
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('utf-8')
|
53
|
+
EscapeUtils.unescape_uri(str).encoding.should eql(Encoding.find('utf-8'))
|
63
54
|
end
|
64
55
|
end
|
65
56
|
end
|
data/spec/url/escape_spec.rb
CHANGED
@@ -36,27 +36,18 @@ describe EscapeUtils, "escape_url" do
|
|
36
36
|
|
37
37
|
# NOTE: from Rack's test suite
|
38
38
|
it "should escape correctly for multibyte characters" do
|
39
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
40
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
39
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
41
40
|
EscapeUtils.escape_url(matz_name).should eql('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8')
|
42
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
43
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
41
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
44
42
|
EscapeUtils.escape_url(matz_name_sep).should eql('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8')
|
45
43
|
end
|
46
44
|
|
47
45
|
if RUBY_VERSION =~ /^1.9/
|
48
|
-
it "should
|
49
|
-
|
50
|
-
str = "http://www.homerun.com/"
|
51
|
-
str = str.encode('us-ascii')
|
46
|
+
it "return value should be in original string's encoding" do
|
47
|
+
str = "http://www.homerun.com/".encode('us-ascii')
|
52
48
|
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
53
|
-
|
54
|
-
|
55
|
-
it "should use Encoding.default_internal" do
|
56
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
57
|
-
EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
58
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
59
|
-
EscapeUtils.escape_url("http://www.homerun.com/").encoding.should eql(Encoding.default_internal)
|
49
|
+
str = "http://www.homerun.com/".encode('utf-8')
|
50
|
+
EscapeUtils.escape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
60
51
|
end
|
61
52
|
end
|
62
53
|
end
|
data/spec/url/unescape_spec.rb
CHANGED
@@ -39,27 +39,18 @@ describe EscapeUtils, "unescape_url" do
|
|
39
39
|
|
40
40
|
# NOTE: from Rack's test suite
|
41
41
|
it "should unescape correctly for multibyte characters" do
|
42
|
-
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8"
|
43
|
-
matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
|
42
|
+
matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8" # Matsumoto
|
44
43
|
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8').should eql(matz_name)
|
45
|
-
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8"
|
46
|
-
matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
|
44
|
+
matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8" # Matsu moto
|
47
45
|
EscapeUtils.unescape_url('%E3%81%BE%E3%81%A4%20%E3%82%82%E3%81%A8').should eql(matz_name_sep)
|
48
46
|
end
|
49
47
|
|
50
48
|
if RUBY_VERSION =~ /^1.9/
|
51
|
-
it "should
|
52
|
-
|
53
|
-
str = "http%3A%2F%2Fwww.homerun.com%2F"
|
54
|
-
str = str.encode('us-ascii')
|
49
|
+
it "return value should be in original string's encoding" do
|
50
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('us-ascii')
|
55
51
|
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('us-ascii'))
|
56
|
-
|
57
|
-
|
58
|
-
it "should use Encoding.default_internal" do
|
59
|
-
Encoding.default_internal = Encoding.find('utf-8')
|
60
|
-
EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
61
|
-
Encoding.default_internal = Encoding.find('us-ascii')
|
62
|
-
EscapeUtils.unescape_url("http%3A%2F%2Fwww.homerun.com%2F").encoding.should eql(Encoding.default_internal)
|
52
|
+
str = "http%3A%2F%2Fwww.homerun.com%2F".encode('utf-8')
|
53
|
+
EscapeUtils.unescape_url(str).encoding.should eql(Encoding.find('utf-8'))
|
63
54
|
end
|
64
55
|
end
|
65
56
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escape_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Lopez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-09 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
requirements: []
|
202
202
|
|
203
203
|
rubyforge_project:
|
204
|
-
rubygems_version: 1.
|
204
|
+
rubygems_version: 1.6.1
|
205
205
|
signing_key:
|
206
206
|
specification_version: 3
|
207
207
|
summary: Faster string escaping routines for your web apps
|