date 1.0.0 → 2.0.0

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

Potentially problematic release.


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

@@ -40,9 +40,9 @@ RUBY_EXTERN unsigned long ruby_scan_digits(const char *str, ssize_t len, int bas
40
40
  #define f_sub_bang(s,r,x) rb_funcall(s, rb_intern("sub!"), 2, r, x)
41
41
  #define f_gsub_bang(s,r,x) rb_funcall(s, rb_intern("gsub!"), 2, r, x)
42
42
 
43
- #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
44
- #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
45
- #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
43
+ #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k"")), v)
44
+ #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k"")))
45
+ #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k"")))
46
46
 
47
47
  #define cstr2num(s) rb_cstr_to_inum(s, 10, 0)
48
48
  #define str2num(s) rb_str_to_inum(s, 10, 0)
@@ -66,7 +66,13 @@ static const char abbr_months[][4] = {
66
66
  #define asubt_string() rb_str_new("\024", 1)
67
67
  #endif
68
68
 
69
- #define DECDIGIT "0123456789"
69
+ static size_t
70
+ digit_span(const char *s, const char *e)
71
+ {
72
+ size_t i = 0;
73
+ while (s + i < e && isdigit(s[i])) i++;
74
+ return i;
75
+ }
70
76
 
71
77
  static void
72
78
  s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
@@ -92,7 +98,7 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
92
98
  y = d;
93
99
  d = Qnil;
94
100
  }
95
- if (!NIL_P(d) && *RSTRING_PTR(d) == '\'') {
101
+ if (!NIL_P(d) && RSTRING_LEN(d) > 0 && *RSTRING_PTR(d) == '\'') {
96
102
  y = d;
97
103
  d = Qnil;
98
104
  }
@@ -103,17 +109,20 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
103
109
  size_t l;
104
110
 
105
111
  s = RSTRING_PTR(y);
106
- while (!issign((unsigned char)*s) && !isdigit((unsigned char)*s))
112
+ ep = RSTRING_END(y);
113
+ while (s < ep && !issign(*s) && !isdigit(*s))
107
114
  s++;
115
+ if (s >= ep) goto no_date;
108
116
  bp = s;
109
117
  if (issign((unsigned char)*s))
110
118
  s++;
111
- l = strspn(s, DECDIGIT);
119
+ l = digit_span(s, ep);
112
120
  ep = s + l;
113
121
  if (*ep) {
114
122
  y = d;
115
123
  d = rb_str_new(bp, ep - bp);
116
124
  }
125
+ no_date:;
117
126
  }
118
127
 
119
128
  if (!NIL_P(m)) {
@@ -152,8 +161,10 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
152
161
  VALUE iy;
153
162
 
154
163
  s = RSTRING_PTR(y);
155
- while (!issign((unsigned char)*s) && !isdigit((unsigned char)*s))
164
+ ep = RSTRING_END(y);
165
+ while (s < ep && !issign(*s) && !isdigit(*s))
156
166
  s++;
167
+ if (s >= ep) goto no_year;
157
168
  bp = s;
158
169
  if (issign(*s)) {
159
170
  s++;
@@ -161,7 +172,7 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
161
172
  }
162
173
  if (sign)
163
174
  c = Qfalse;
164
- l = strspn(s, DECDIGIT);
175
+ l = digit_span(s, ep);
165
176
  ep = s + l;
166
177
  if (l > 2)
167
178
  c = Qfalse;
@@ -175,6 +186,7 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
175
186
  ALLOCV_END(vbuf);
176
187
  }
177
188
  set_hash("year", iy);
189
+ no_year:;
178
190
  }
179
191
 
180
192
  if (bc)
@@ -186,10 +198,12 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
186
198
  VALUE im;
187
199
 
188
200
  s = RSTRING_PTR(m);
189
- while (!isdigit((unsigned char)*s))
201
+ ep = RSTRING_END(m);
202
+ while (s < ep && !isdigit(*s))
190
203
  s++;
204
+ if (s >= ep) goto no_month;
191
205
  bp = s;
192
- l = strspn(s, DECDIGIT);
206
+ l = digit_span(s, ep);
193
207
  ep = s + l;
194
208
  {
195
209
  char *buf;
@@ -201,6 +215,7 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
201
215
  ALLOCV_END(vbuf);
202
216
  }
203
217
  set_hash("mon", im);
218
+ no_month:;
204
219
  }
205
220
 
206
221
  if (!NIL_P(d)) {
@@ -209,10 +224,12 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
209
224
  VALUE id;
210
225
 
211
226
  s = RSTRING_PTR(d);
212
- while (!isdigit((unsigned char)*s))
227
+ ep = RSTRING_END(d);
228
+ while (s < ep && !isdigit(*s))
213
229
  s++;
230
+ if (s >= ep) goto no_mday;
214
231
  bp = s;
215
- l = strspn(s, DECDIGIT);
232
+ l = digit_span(s, ep);
216
233
  ep = s + l;
217
234
  {
218
235
  char *buf;
@@ -224,6 +241,7 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
224
241
  ALLOCV_END(vbuf);
225
242
  }
226
243
  set_hash("mday", id);
244
+ no_mday:;
227
245
  }
228
246
 
229
247
  if (!NIL_P(c))
@@ -263,18 +281,18 @@ regcomp(const char *source, long len, int opt)
263
281
  }
264
282
 
265
283
  #define REGCOMP(pat,opt) \
266
- { \
284
+ do { \
267
285
  if (NIL_P(pat)) \
268
286
  pat = regcomp(pat##_source, sizeof pat##_source - 1, opt); \
269
- }
287
+ } while (0)
270
288
 
271
289
  #define REGCOMP_0(pat) REGCOMP(pat, 0)
272
290
  #define REGCOMP_I(pat) REGCOMP(pat, ONIG_OPTION_IGNORECASE)
273
291
 
274
292
  #define MATCH(s,p,c) \
275
- { \
293
+ do { \
276
294
  return match(s, p, hash, c); \
277
- }
295
+ } while (0)
278
296
 
279
297
  static int
280
298
  match(VALUE str, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))
@@ -314,30 +332,30 @@ subx(VALUE str, VALUE rep, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))
314
332
  }
315
333
 
316
334
  #define SUBS(s,p,c) \
317
- { \
335
+ do { \
318
336
  return subx(s, asp_string(), p, hash, c); \
319
- }
337
+ } while (0)
320
338
 
321
339
  #ifdef TIGHT_PARSER
322
340
  #define SUBA(s,p,c) \
323
- { \
341
+ do { \
324
342
  return subx(s, asuba_string(), p, hash, c); \
325
- }
343
+ } while (0)
326
344
 
327
345
  #define SUBB(s,p,c) \
328
- { \
346
+ do { \
329
347
  return subx(s, asubb_string(), p, hash, c); \
330
- }
348
+ } while (0)
331
349
 
332
350
  #define SUBW(s,p,c) \
333
- { \
351
+ do { \
334
352
  return subx(s, asubw_string(), p, hash, c); \
335
- }
353
+ } while (0)
336
354
 
337
355
  #define SUBT(s,p,c) \
338
- { \
356
+ do { \
339
357
  return subx(s, asubt_string(), p, hash, c); \
340
- }
358
+ } while (0)
341
359
  #endif
342
360
 
343
361
  #include "zonetab.h"
@@ -706,16 +724,14 @@ parse_era(VALUE str, VALUE hash)
706
724
  static int
707
725
  check_year_width(VALUE y)
708
726
  {
709
- char *s;
710
- size_t l;
727
+ const char *s;
728
+ long l;
711
729
 
730
+ l = RSTRING_LEN(y);
731
+ if (l < 2) return 0;
712
732
  s = RSTRING_PTR(y);
713
- l = strcspn(s, DECDIGIT);
714
- s += l;
715
- l = strspn(s, DECDIGIT);
716
- if (l != 2)
717
- return 0;
718
- return 1;
733
+ if (!isdigit(s[1])) return 0;
734
+ return (l == 2 || !isdigit(s[2]));
719
735
  }
720
736
 
721
737
  static int
@@ -79,14 +79,17 @@ read_digits(const char *s, VALUE *n, size_t width)
79
79
  {
80
80
  size_t l;
81
81
 
82
- l = strspn(s, "0123456789");
82
+ if (!width)
83
+ return 0;
84
+
85
+ l = 0;
86
+ while (ISDIGIT(s[l])) {
87
+ if (++l == width) break;
88
+ }
83
89
 
84
90
  if (l == 0)
85
91
  return 0;
86
92
 
87
- if (width < l)
88
- l = width;
89
-
90
93
  if ((4 * l * sizeof(char)) <= (sizeof(long)*CHAR_BIT)) {
91
94
  const char *os = s;
92
95
  long v;
@@ -113,26 +116,26 @@ read_digits(const char *s, VALUE *n, size_t width)
113
116
  }
114
117
  }
115
118
 
116
- #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
117
- #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
118
- #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
119
+ #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k"")), v)
120
+ #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k"")))
121
+ #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k"")))
119
122
 
120
123
  #define fail() \
121
- { \
124
+ do { \
122
125
  set_hash("_fail", Qtrue); \
123
126
  return 0; \
124
- }
127
+ } while (0)
125
128
 
126
129
  #define fail_p() (!NIL_P(ref_hash("_fail")))
127
130
 
128
131
  #define READ_DIGITS(n,w) \
129
- { \
132
+ do { \
130
133
  size_t l; \
131
134
  l = read_digits(&str[si], &n, w); \
132
135
  if (l == 0) \
133
136
  fail(); \
134
137
  si += l; \
135
- }
138
+ } while (0)
136
139
 
137
140
  #define READ_DIGITS_MAX(n) READ_DIGITS(n, LONG_MAX)
138
141
 
@@ -147,14 +150,14 @@ valid_range_p(VALUE v, int a, int b)
147
150
  }
148
151
 
149
152
  #define recur(fmt) \
150
- { \
153
+ do { \
151
154
  size_t l; \
152
155
  l = date__strptime_internal(&str[si], slen - si, \
153
156
  fmt, sizeof fmt - 1, hash); \
154
157
  if (fail_p()) \
155
158
  return 0; \
156
159
  si += l; \
157
- }
160
+ } while (0)
158
161
 
159
162
  VALUE date_zone_to_diff(VALUE);
160
163
 
@@ -237,9 +240,9 @@ date__strptime_internal(const char *str, size_t slen,
237
240
  VALUE n;
238
241
 
239
242
  if (NUM_PATTERN_P())
240
- READ_DIGITS(n, 2)
243
+ READ_DIGITS(n, 2);
241
244
  else
242
- READ_DIGITS_MAX(n)
245
+ READ_DIGITS_MAX(n);
243
246
  set_hash("_cent", n);
244
247
  goto matched;
245
248
  }
@@ -278,9 +281,9 @@ date__strptime_internal(const char *str, size_t slen,
278
281
  VALUE n;
279
282
 
280
283
  if (NUM_PATTERN_P())
281
- READ_DIGITS(n, 4)
284
+ READ_DIGITS(n, 4);
282
285
  else
283
- READ_DIGITS_MAX(n)
286
+ READ_DIGITS_MAX(n);
284
287
  set_hash("cwyear", n);
285
288
  goto matched;
286
289
  }
@@ -358,9 +361,9 @@ date__strptime_internal(const char *str, size_t slen,
358
361
  }
359
362
  osi = si;
360
363
  if (NUM_PATTERN_P())
361
- READ_DIGITS(n, c == 'L' ? 3 : 9)
364
+ READ_DIGITS(n, c == 'L' ? 3 : 9);
362
365
  else
363
- READ_DIGITS_MAX(n)
366
+ READ_DIGITS_MAX(n);
364
367
  if (sign == -1)
365
368
  n = f_negate(n);
366
369
  set_hash("sec_fraction",
@@ -426,9 +429,7 @@ date__strptime_internal(const char *str, size_t slen,
426
429
  if (sign == -1)
427
430
  n = f_negate(n);
428
431
  set_hash("seconds",
429
- rb_rational_new2(n,
430
- f_expt(INT2FIX(10),
431
- INT2FIX(3))));
432
+ rb_rational_new2(n, INT2FIX(1000)));
432
433
  goto matched;
433
434
  }
434
435
 
@@ -529,24 +530,24 @@ date__strptime_internal(const char *str, size_t slen,
529
530
  goto matched;
530
531
 
531
532
  case 'Y':
532
- {
533
- VALUE n;
534
- int sign = 1;
535
-
536
- if (issign(str[si])) {
537
- if (str[si] == '-')
538
- sign = -1;
539
- si++;
540
- }
541
- if (NUM_PATTERN_P())
542
- READ_DIGITS(n, 4)
543
- else
544
- READ_DIGITS_MAX(n)
533
+ {
534
+ VALUE n;
535
+ int sign = 1;
536
+
537
+ if (issign(str[si])) {
538
+ if (str[si] == '-')
539
+ sign = -1;
540
+ si++;
541
+ }
542
+ if (NUM_PATTERN_P())
543
+ READ_DIGITS(n, 4);
544
+ else
545
+ READ_DIGITS_MAX(n);
545
546
  if (sign == -1)
546
547
  n = f_negate(n);
547
- set_hash("year", n);
548
- goto matched;
549
- }
548
+ set_hash("year", n);
549
+ goto matched;
550
+ }
550
551
 
551
552
  case 'y':
552
553
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadayoshi Funaba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -61,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.7.3
64
+ rubygems_version: 3.0.2
66
65
  signing_key:
67
66
  specification_version: 4
68
67
  summary: A subclass of Object includes Comparable module for handling dates.