stringio 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of stringio might be problematic. Click here for more details.

Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/stringio/stringio.c +16 -8
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7968119a0c6ab844f6b3ad11ffa51f7b4065af10a2d73ad79ecbee496e8f352a
4
- data.tar.gz: 11c767a84c56493cf7cd0adf6fddda81f3d6a630ad947c3eddc385b00587311e
3
+ metadata.gz: 864faa7f9cd87b42a0aa0c6fde4baf5770280a51f269466c8e05f08a65a465e2
4
+ data.tar.gz: 388ee6afc1e098f6588d49e10cfc6c29d0299c6bd50932f667e1b15f666862b0
5
5
  SHA512:
6
- metadata.gz: 69ecd5af25b6334a5dfc7013779f57f6171dec1694f3f0272f05ec51404edc5d4ccac8df78c9f28c8c635bf49afffc2db50dad13ea8a78bf019265390ec0c121
7
- data.tar.gz: 7ae636d1c423605e568349440f6a2e185a05bb1402569f185456dde23130eeefacd7a37768b6ed64ae99fc578799aabb4aeeede35df4d555b75d6cbbdebd7570
6
+ metadata.gz: a6bb2fa90aa17aa3e3fe3c5ddde9e6117cfe100232b1805470e10d444aa57edccd9d08f08cde813004ef8afe6ecc6d095e17e691483d74fcadfdb09c911e09ce
7
+ data.tar.gz: 130f35508424d508a8362b2689a698877f8e999b8c777bb16626dc496665bd3b5aa191e2dc011245ec428c08aefbdde017f520447375843cc12a77a0dcd893c4
@@ -11,7 +11,7 @@
11
11
 
12
12
  **********************************************************************/
13
13
 
14
- #define STRINGIO_VERSION "0.1.0"
14
+ #define STRINGIO_VERSION "0.1.3"
15
15
 
16
16
  #include "ruby.h"
17
17
  #include "ruby/io.h"
@@ -363,7 +363,12 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
363
363
  rb_str_resize(string, 0);
364
364
  }
365
365
  ptr->string = string;
366
- ptr->enc = convconfig.enc;
366
+ if (argc == 1) {
367
+ ptr->enc = rb_enc_get(string);
368
+ }
369
+ else {
370
+ ptr->enc = convconfig.enc;
371
+ }
367
372
  ptr->pos = 0;
368
373
  ptr->lineno = 0;
369
374
  if (ptr->flags & FMODE_SETENC_BY_BOM) set_encoding_by_bom(ptr);
@@ -1424,13 +1429,18 @@ strio_write(VALUE self, VALUE str)
1424
1429
  long len, olen;
1425
1430
  rb_encoding *enc, *enc2;
1426
1431
  rb_encoding *const ascii8bit = rb_ascii8bit_encoding();
1432
+ rb_encoding *usascii = 0;
1427
1433
 
1428
1434
  if (!RB_TYPE_P(str, T_STRING))
1429
1435
  str = rb_obj_as_string(str);
1430
1436
  enc = get_enc(ptr);
1431
1437
  enc2 = rb_enc_get(str);
1432
- if (enc != enc2 && enc != ascii8bit) {
1433
- str = rb_str_conv_enc(str, enc2, enc);
1438
+ if (enc != enc2 && enc != ascii8bit && enc != (usascii = rb_usascii_encoding())) {
1439
+ VALUE converted = rb_str_conv_enc(str, enc2, enc);
1440
+ if (converted == str && enc2 != ascii8bit && enc2 != usascii) { /* conversion failed */
1441
+ rb_enc_check(rb_enc_from_encoding(enc), str);
1442
+ }
1443
+ str = converted;
1434
1444
  }
1435
1445
  len = RSTRING_LEN(str);
1436
1446
  if (len == 0) return 0;
@@ -1527,7 +1537,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
1527
1537
  long len;
1528
1538
  int binary = 0;
1529
1539
 
1530
- rb_check_arity(argc, 0, 2);
1531
1540
  switch (argc) {
1532
1541
  case 2:
1533
1542
  str = argv[1];
@@ -1567,6 +1576,8 @@ strio_read(int argc, VALUE *argv, VALUE self)
1567
1576
  len -= ptr->pos;
1568
1577
  }
1569
1578
  break;
1579
+ default:
1580
+ rb_error_arity(argc, 0, 2);
1570
1581
  }
1571
1582
  if (NIL_P(str)) {
1572
1583
  rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
@@ -1759,9 +1770,6 @@ strio_set_encoding_by_bom(VALUE self)
1759
1770
  {
1760
1771
  struct StringIO *ptr = StringIO(self);
1761
1772
 
1762
- if (ptr->enc) {
1763
- rb_raise(rb_eArgError, "encoding conversion is set");
1764
- }
1765
1773
  if (!set_encoding_by_bom(ptr)) return Qnil;
1766
1774
  return rb_enc_from_encoding(ptr->enc);
1767
1775
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -38,7 +38,7 @@ homepage: https://github.com/ruby/stringio
38
38
  licenses:
39
39
  - BSD-2-Clause
40
40
  metadata: {}
41
- post_install_message:
41
+ post_install_message:
42
42
  rdoc_options: []
43
43
  require_paths:
44
44
  - lib
@@ -53,8 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.6'
55
55
  requirements: []
56
- rubygems_version: 3.0.3
57
- signing_key:
56
+ rubygems_version: 3.2.0.pre1
57
+ signing_key:
58
58
  specification_version: 4
59
59
  summary: Pseudo IO on String
60
60
  test_files: []