stringio 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +19 -0
  3. data/ext/stringio/stringio.c +23 -13
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f8291051ef78bfdd817200ff02c25db3e2fa495d9b4a164c9737511d6eadb38
4
- data.tar.gz: 8593995f8dbb66e6a3dc9f2755f97d0cc05e2d363e6cd027cc15a7d46deaf60f
3
+ metadata.gz: 89f7a19f0a8689e3fa7ceae8a0139eab614a14f64f2d1f5831c0d012d3b49dac
4
+ data.tar.gz: 71b2022cc337d594566c0dfcb215bc1f3d4949747c97ffb984ea0613f67d58aa
5
5
  SHA512:
6
- metadata.gz: 5060643c29e66ccc88df7a7ab4c19943d89ce3779641b9be7e0cfc61ce79db7c53af06367875b1892b80f31d98be32d10da2590445cb86425b7d89f285a30b5f
7
- data.tar.gz: 1a6dcf694eaa38dd0d939b8db9cb4f29cc96db93ac545f5f06d6354ad5e75f92fb9807f529f54ae6801a3f791e7139db7ad371bf8efd6b7ca34f45f61fb10429
6
+ metadata.gz: e6aa9ba1567fe2ea15f973a81ef8ae215be4ea7b88013dd9a4d9e8cbd8d1d0381dd70980ffb049d8b4283e0b1e6e586ef840618c8f129f1182c71bfa95847824
7
+ data.tar.gz: ed2fd455cbe0f072ef020f2b6a114ae192a8a86509cebcb927fb4c7b9754551bdda8519ebc7aa21b6cbf2b3c0cab4170e5017c0468ad4431ea4b9eaf9c473825
data/NEWS.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # News
2
2
 
3
+ ## 3.1.2 - 2024-11-07
4
+
5
+ ### Improvements
6
+
7
+ * JRuby: Added support for detecting encoding by BOM.
8
+ * GH-100
9
+ * GH-101
10
+
11
+ ### Fixes
12
+
13
+ * CRuby: Fixed a bug that unknown memory may be used by
14
+ `StringIO#ungetc`/`StringIO#ungetbyte`.
15
+ * https://hackerone.com/reports/2805165
16
+ * Reported by manun.
17
+
18
+ ### Thanks
19
+
20
+ * manun
21
+
3
22
  ## 3.1.1 - 2024-06-13
4
23
 
5
24
  ### Improvements
@@ -13,7 +13,7 @@
13
13
  **********************************************************************/
14
14
 
15
15
  static const char *const
16
- STRINGIO_VERSION = "3.1.1";
16
+ STRINGIO_VERSION = "3.1.2";
17
17
 
18
18
  #include <stdbool.h>
19
19
 
@@ -930,6 +930,18 @@ strio_extend(struct StringIO *ptr, long pos, long len)
930
930
  }
931
931
  }
932
932
 
933
+ static void
934
+ strio_unget_string(struct StringIO *ptr, VALUE c)
935
+ {
936
+ const char *cp = NULL;
937
+ long cl = RSTRING_LEN(c);
938
+ if (cl > 0) {
939
+ if (c != ptr->string) cp = RSTRING_PTR(c);
940
+ strio_unget_bytes(ptr, cp, cl);
941
+ RB_GC_GUARD(c);
942
+ }
943
+ }
944
+
933
945
  /*
934
946
  * call-seq:
935
947
  * ungetc(character) -> nil
@@ -952,19 +964,22 @@ strio_ungetc(VALUE self, VALUE c)
952
964
 
953
965
  enc = rb_enc_get(ptr->string);
954
966
  len = rb_enc_codelen(cc, enc);
955
- if (len <= 0) rb_enc_uint_chr(cc, enc);
967
+ if (len <= 0) {
968
+ rb_enc_uint_chr(cc, enc); /* to raise an exception */
969
+ UNREACHABLE;
970
+ }
956
971
  rb_enc_mbcput(cc, buf, enc);
957
972
  return strio_unget_bytes(ptr, buf, len);
958
973
  }
959
974
  else {
960
- SafeStringValue(c);
975
+ StringValue(c);
976
+ if (RSTRING_LEN(c) == 0) return Qnil;
961
977
  enc = rb_enc_get(ptr->string);
962
978
  enc2 = rb_enc_get(c);
963
979
  if (enc != enc2 && enc != rb_ascii8bit_encoding()) {
964
980
  c = rb_str_conv_enc(c, enc2, enc);
965
981
  }
966
- strio_unget_bytes(ptr, RSTRING_PTR(c), RSTRING_LEN(c));
967
- RB_GC_GUARD(c);
982
+ strio_unget_string(ptr, c);
968
983
  return Qnil;
969
984
  }
970
985
  }
@@ -991,13 +1006,8 @@ strio_ungetbyte(VALUE self, VALUE c)
991
1006
  strio_unget_bytes(ptr, &cc, 1);
992
1007
  }
993
1008
  else {
994
- long cl;
995
- SafeStringValue(c);
996
- cl = RSTRING_LEN(c);
997
- if (cl > 0) {
998
- strio_unget_bytes(ptr, RSTRING_PTR(c), cl);
999
- RB_GC_GUARD(c);
1000
- }
1009
+ StringValue(c);
1010
+ strio_unget_string(ptr, c);
1001
1011
  }
1002
1012
  return Qnil;
1003
1013
  }
@@ -1028,7 +1038,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, long cl)
1028
1038
  if (rest > cl) memset(s + len, 0, rest - cl);
1029
1039
  pos -= cl;
1030
1040
  }
1031
- memcpy(s + pos, cp, cl);
1041
+ memcpy(s + pos, (cp ? cp : s), cl);
1032
1042
  ptr->pos = pos;
1033
1043
  return Qnil;
1034
1044
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-06-13 00:00:00.000000000 Z
12
+ date: 2024-11-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Pseudo `IO` class from/to `String`.
15
15
  email:
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.5.11
61
+ rubygems_version: 3.5.22
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Pseudo IO on String