date 3.1.1 → 3.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/date/date_core.c +296 -88
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 023fa4cf6c7f68a0f3dc03031ad864c1fe3f748234c20e1bffc1ee2cc9b41ae8
4
- data.tar.gz: 7851c6cccbc8275113236208e093689f62882abf40ff5c7911ca146597d8457a
3
+ metadata.gz: 33ef20bebc298ad26d350db0e6511f2dbc084402c0d118e5f70f5f77230df222
4
+ data.tar.gz: d6ad174792f8032aab382cb21c10cc0cdbcc77e6f32c4105ff51736251eea43f
5
5
  SHA512:
6
- metadata.gz: 763d8778816f56ec3f5c2dd8cc81f5ba1c07c9adc4216156faf10170276bd15c07dda24313e4925e4003e7aeb399a8115fe68129d3b3d10833d65443e9de760d
7
- data.tar.gz: c5bb10ba72106dcdb7363fb988e38cb542c27a09dfc19b878966184750845da6e80f7033feb57e72dd9cf1ec23dd4cf0788d765e1f596fe7961dbcaec7905711
6
+ metadata.gz: 9e7b5ac465831a3fc501d72d1ef576a8b3d4791553047a0516c1e6dc7190eb418acb65521afda41a0ff6fe5ca3f09011e04ba27f3b30b2d511bffb177704306c
7
+ data.tar.gz: 8c020832fac18b494a6d2ec7de441fd8d3cc90ffa44cc33196ef2fa0ad1e1ee1ff8af63c183250c39d10ccde9a478246303500d53c61483319d0f62c502d8c4b
data/ext/date/date_core.c CHANGED
@@ -4328,12 +4328,37 @@ date_s_strptime(int argc, VALUE *argv, VALUE klass)
4328
4328
 
4329
4329
  VALUE date__parse(VALUE str, VALUE comp);
4330
4330
 
4331
+ static size_t
4332
+ get_limit(VALUE opt)
4333
+ {
4334
+ if (!NIL_P(opt)) {
4335
+ VALUE limit = rb_hash_aref(opt, ID2SYM(rb_intern("limit")));
4336
+ if (NIL_P(limit)) return SIZE_MAX;
4337
+ return NUM2SIZET(limit);
4338
+ }
4339
+ return 128;
4340
+ }
4341
+
4342
+ static void
4343
+ check_limit(VALUE str, VALUE opt)
4344
+ {
4345
+ StringValue(str);
4346
+ size_t slen = RSTRING_LEN(str);
4347
+ size_t limit = get_limit(opt);
4348
+ if (slen > limit) {
4349
+ rb_raise(rb_eArgError,
4350
+ "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
4351
+ }
4352
+ }
4353
+
4331
4354
  static VALUE
4332
4355
  date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4333
4356
  {
4334
- VALUE vstr, vcomp, hash;
4357
+ VALUE vstr, vcomp, hash, opt;
4335
4358
 
4336
- rb_scan_args(argc, argv, "11", &vstr, &vcomp);
4359
+ rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
4360
+ if (!NIL_P(opt)) argc--;
4361
+ check_limit(vstr, opt);
4337
4362
  StringValue(vstr);
4338
4363
  if (!rb_enc_str_asciicompat_p(vstr))
4339
4364
  rb_raise(rb_eArgError,
@@ -4348,7 +4373,7 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4348
4373
 
4349
4374
  /*
4350
4375
  * call-seq:
4351
- * Date._parse(string[, comp=true]) -> hash
4376
+ * Date._parse(string[, comp=true], limit: 128) -> hash
4352
4377
  *
4353
4378
  * Parses the given representation of date and time, and returns a
4354
4379
  * hash of parsed elements.
@@ -4363,6 +4388,10 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4363
4388
  * it full.
4364
4389
  *
4365
4390
  * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4391
+ *
4392
+ * Raise an ArgumentError when the string length is longer than _limit_.
4393
+ * You can stop this check by passing `limit: nil`, but note that
4394
+ * it may take a long time to parse.
4366
4395
  */
4367
4396
  static VALUE
4368
4397
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4372,7 +4401,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4372
4401
 
4373
4402
  /*
4374
4403
  * call-seq:
4375
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
4404
+ * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4376
4405
  *
4377
4406
  * Parses the given representation of date and time, and creates a
4378
4407
  * date object.
@@ -4389,13 +4418,18 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4389
4418
  * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4390
4419
  * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4391
4420
  * Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
4421
+ *
4422
+ * Raise an ArgumentError when the string length is longer than _limit_.
4423
+ * You can stop this check by passing `limit: nil`, but note that
4424
+ * it may take a long time to parse.
4392
4425
  */
4393
4426
  static VALUE
4394
4427
  date_s_parse(int argc, VALUE *argv, VALUE klass)
4395
4428
  {
4396
- VALUE str, comp, sg;
4429
+ VALUE str, comp, sg, opt;
4397
4430
 
4398
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
4431
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
4432
+ if (!NIL_P(opt)) argc--;
4399
4433
 
4400
4434
  switch (argc) {
4401
4435
  case 0:
@@ -4407,11 +4441,12 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4407
4441
  }
4408
4442
 
4409
4443
  {
4410
- VALUE argv2[2], hash;
4411
-
4412
- argv2[0] = str;
4413
- argv2[1] = comp;
4414
- hash = date_s__parse(2, argv2, klass);
4444
+ int argc2 = 2;
4445
+ VALUE argv2[3];
4446
+ argv2[0] = str;
4447
+ argv2[1] = comp;
4448
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4449
+ VALUE hash = date_s__parse(argc2, argv2, klass);
4415
4450
  return d_new_by_frags(klass, hash, sg);
4416
4451
  }
4417
4452
  }
@@ -4425,19 +4460,28 @@ VALUE date__jisx0301(VALUE);
4425
4460
 
4426
4461
  /*
4427
4462
  * call-seq:
4428
- * Date._iso8601(string) -> hash
4463
+ * Date._iso8601(string, limit: 128) -> hash
4429
4464
  *
4430
4465
  * Returns a hash of parsed elements.
4466
+ *
4467
+ * Raise an ArgumentError when the string length is longer than _limit_.
4468
+ * You can stop this check by passing `limit: nil`, but note that
4469
+ * it may take a long time to parse.
4431
4470
  */
4432
4471
  static VALUE
4433
- date_s__iso8601(VALUE klass, VALUE str)
4472
+ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4434
4473
  {
4474
+ VALUE str, opt;
4475
+
4476
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4477
+ check_limit(str, opt);
4478
+
4435
4479
  return date__iso8601(str);
4436
4480
  }
4437
4481
 
4438
4482
  /*
4439
4483
  * call-seq:
4440
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
4484
+ * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4441
4485
  *
4442
4486
  * Creates a new Date object by parsing from a string according to
4443
4487
  * some typical ISO 8601 formats.
@@ -4445,13 +4489,18 @@ date_s__iso8601(VALUE klass, VALUE str)
4445
4489
  * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4446
4490
  * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4447
4491
  * Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
4492
+ *
4493
+ * Raise an ArgumentError when the string length is longer than _limit_.
4494
+ * You can stop this check by passing `limit: nil`, but note that
4495
+ * it may take a long time to parse.
4448
4496
  */
4449
4497
  static VALUE
4450
4498
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4451
4499
  {
4452
- VALUE str, sg;
4500
+ VALUE str, sg, opt;
4453
4501
 
4454
- rb_scan_args(argc, argv, "02", &str, &sg);
4502
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4503
+ if (!NIL_P(opt)) argc--;
4455
4504
 
4456
4505
  switch (argc) {
4457
4506
  case 0:
@@ -4461,38 +4510,56 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4461
4510
  }
4462
4511
 
4463
4512
  {
4464
- VALUE hash = date_s__iso8601(klass, str);
4513
+ int argc2 = 1;
4514
+ VALUE argv2[2];
4515
+ argv2[0] = str;
4516
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4517
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
4465
4518
  return d_new_by_frags(klass, hash, sg);
4466
4519
  }
4467
4520
  }
4468
4521
 
4469
4522
  /*
4470
4523
  * call-seq:
4471
- * Date._rfc3339(string) -> hash
4524
+ * Date._rfc3339(string, limit: 128) -> hash
4472
4525
  *
4473
4526
  * Returns a hash of parsed elements.
4527
+ *
4528
+ * Raise an ArgumentError when the string length is longer than _limit_.
4529
+ * You can stop this check by passing `limit: nil`, but note that
4530
+ * it may take a long time to parse.
4474
4531
  */
4475
4532
  static VALUE
4476
- date_s__rfc3339(VALUE klass, VALUE str)
4533
+ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4477
4534
  {
4535
+ VALUE str, opt;
4536
+
4537
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4538
+ check_limit(str, opt);
4539
+
4478
4540
  return date__rfc3339(str);
4479
4541
  }
4480
4542
 
4481
4543
  /*
4482
4544
  * call-seq:
4483
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
4545
+ * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4484
4546
  *
4485
4547
  * Creates a new Date object by parsing from a string according to
4486
4548
  * some typical RFC 3339 formats.
4487
4549
  *
4488
4550
  * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
4551
+ *
4552
+ * Raise an ArgumentError when the string length is longer than _limit_.
4553
+ * You can stop this check by passing `limit: nil`, but note that
4554
+ * it may take a long time to parse.
4489
4555
  */
4490
4556
  static VALUE
4491
4557
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4492
4558
  {
4493
- VALUE str, sg;
4559
+ VALUE str, sg, opt;
4494
4560
 
4495
- rb_scan_args(argc, argv, "02", &str, &sg);
4561
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4562
+ if (!NIL_P(opt)) argc--;
4496
4563
 
4497
4564
  switch (argc) {
4498
4565
  case 0:
@@ -4502,38 +4569,56 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4502
4569
  }
4503
4570
 
4504
4571
  {
4505
- VALUE hash = date_s__rfc3339(klass, str);
4572
+ int argc2 = 1;
4573
+ VALUE argv2[2];
4574
+ argv2[0] = str;
4575
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4576
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4506
4577
  return d_new_by_frags(klass, hash, sg);
4507
4578
  }
4508
4579
  }
4509
4580
 
4510
4581
  /*
4511
4582
  * call-seq:
4512
- * Date._xmlschema(string) -> hash
4583
+ * Date._xmlschema(string, limit: 128) -> hash
4513
4584
  *
4514
4585
  * Returns a hash of parsed elements.
4586
+ *
4587
+ * Raise an ArgumentError when the string length is longer than _limit_.
4588
+ * You can stop this check by passing `limit: nil`, but note that
4589
+ * it may take a long time to parse.
4515
4590
  */
4516
4591
  static VALUE
4517
- date_s__xmlschema(VALUE klass, VALUE str)
4592
+ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4518
4593
  {
4594
+ VALUE str, opt;
4595
+
4596
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4597
+ check_limit(str, opt);
4598
+
4519
4599
  return date__xmlschema(str);
4520
4600
  }
4521
4601
 
4522
4602
  /*
4523
4603
  * call-seq:
4524
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
4604
+ * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4525
4605
  *
4526
4606
  * Creates a new Date object by parsing from a string according to
4527
4607
  * some typical XML Schema formats.
4528
4608
  *
4529
4609
  * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4610
+ *
4611
+ * Raise an ArgumentError when the string length is longer than _limit_.
4612
+ * You can stop this check by passing `limit: nil`, but note that
4613
+ * it may take a long time to parse.
4530
4614
  */
4531
4615
  static VALUE
4532
4616
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4533
4617
  {
4534
- VALUE str, sg;
4618
+ VALUE str, sg, opt;
4535
4619
 
4536
- rb_scan_args(argc, argv, "02", &str, &sg);
4620
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4621
+ if (!NIL_P(opt)) argc--;
4537
4622
 
4538
4623
  switch (argc) {
4539
4624
  case 0:
@@ -4543,41 +4628,58 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4543
4628
  }
4544
4629
 
4545
4630
  {
4546
- VALUE hash = date_s__xmlschema(klass, str);
4631
+ int argc2 = 1;
4632
+ VALUE argv2[2];
4633
+ argv2[0] = str;
4634
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4635
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4547
4636
  return d_new_by_frags(klass, hash, sg);
4548
4637
  }
4549
4638
  }
4550
4639
 
4551
4640
  /*
4552
4641
  * call-seq:
4553
- * Date._rfc2822(string) -> hash
4554
- * Date._rfc822(string) -> hash
4642
+ * Date._rfc2822(string, limit: 128) -> hash
4643
+ * Date._rfc822(string, limit: 128) -> hash
4555
4644
  *
4556
4645
  * Returns a hash of parsed elements.
4646
+ *
4647
+ * Raise an ArgumentError when the string length is longer than _limit_.
4648
+ * You can stop this check by passing `limit: nil`, but note that
4649
+ * it may take a long time to parse.
4557
4650
  */
4558
4651
  static VALUE
4559
- date_s__rfc2822(VALUE klass, VALUE str)
4652
+ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4560
4653
  {
4654
+ VALUE str, opt;
4655
+
4656
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4657
+ check_limit(str, opt);
4658
+
4561
4659
  return date__rfc2822(str);
4562
4660
  }
4563
4661
 
4564
4662
  /*
4565
4663
  * call-seq:
4566
- * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4567
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4664
+ * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4665
+ * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4568
4666
  *
4569
4667
  * Creates a new Date object by parsing from a string according to
4570
4668
  * some typical RFC 2822 formats.
4571
4669
  *
4572
4670
  * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4573
4671
  * #=> #<Date: 2001-02-03 ...>
4672
+ *
4673
+ * Raise an ArgumentError when the string length is longer than _limit_.
4674
+ * You can stop this check by passing `limit: nil`, but note that
4675
+ * it may take a long time to parse.
4574
4676
  */
4575
4677
  static VALUE
4576
4678
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4577
4679
  {
4578
- VALUE str, sg;
4680
+ VALUE str, sg, opt;
4579
4681
 
4580
- rb_scan_args(argc, argv, "02", &str, &sg);
4682
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4581
4683
 
4582
4684
  switch (argc) {
4583
4685
  case 0:
@@ -4587,39 +4689,56 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4587
4689
  }
4588
4690
 
4589
4691
  {
4590
- VALUE hash = date_s__rfc2822(klass, str);
4692
+ int argc2 = 1;
4693
+ VALUE argv2[2];
4694
+ argv2[0] = str;
4695
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4696
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4591
4697
  return d_new_by_frags(klass, hash, sg);
4592
4698
  }
4593
4699
  }
4594
4700
 
4595
4701
  /*
4596
4702
  * call-seq:
4597
- * Date._httpdate(string) -> hash
4703
+ * Date._httpdate(string, limit: 128) -> hash
4598
4704
  *
4599
4705
  * Returns a hash of parsed elements.
4706
+ *
4707
+ * Raise an ArgumentError when the string length is longer than _limit_.
4708
+ * You can stop this check by passing `limit: nil`, but note that
4709
+ * it may take a long time to parse.
4600
4710
  */
4601
4711
  static VALUE
4602
- date_s__httpdate(VALUE klass, VALUE str)
4712
+ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4603
4713
  {
4714
+ VALUE str, opt;
4715
+
4716
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4717
+ check_limit(str, opt);
4718
+
4604
4719
  return date__httpdate(str);
4605
4720
  }
4606
4721
 
4607
4722
  /*
4608
4723
  * call-seq:
4609
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
4724
+ * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4610
4725
  *
4611
4726
  * Creates a new Date object by parsing from a string according to
4612
4727
  * some RFC 2616 format.
4613
4728
  *
4614
4729
  * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4615
4730
  * #=> #<Date: 2001-02-03 ...>
4731
+ *
4732
+ * Raise an ArgumentError when the string length is longer than _limit_.
4733
+ * You can stop this check by passing `limit: nil`, but note that
4734
+ * it may take a long time to parse.
4616
4735
  */
4617
4736
  static VALUE
4618
4737
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4619
4738
  {
4620
- VALUE str, sg;
4739
+ VALUE str, sg, opt;
4621
4740
 
4622
- rb_scan_args(argc, argv, "02", &str, &sg);
4741
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4623
4742
 
4624
4743
  switch (argc) {
4625
4744
  case 0:
@@ -4629,26 +4748,39 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4629
4748
  }
4630
4749
 
4631
4750
  {
4632
- VALUE hash = date_s__httpdate(klass, str);
4751
+ int argc2 = 1;
4752
+ VALUE argv2[2];
4753
+ argv2[0] = str;
4754
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4755
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
4633
4756
  return d_new_by_frags(klass, hash, sg);
4634
4757
  }
4635
4758
  }
4636
4759
 
4637
4760
  /*
4638
4761
  * call-seq:
4639
- * Date._jisx0301(string) -> hash
4762
+ * Date._jisx0301(string, limit: 128) -> hash
4640
4763
  *
4641
4764
  * Returns a hash of parsed elements.
4765
+ *
4766
+ * Raise an ArgumentError when the string length is longer than _limit_.
4767
+ * You can stop this check by passing `limit: nil`, but note that
4768
+ * it may take a long time to parse.
4642
4769
  */
4643
4770
  static VALUE
4644
- date_s__jisx0301(VALUE klass, VALUE str)
4771
+ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4645
4772
  {
4773
+ VALUE str, opt;
4774
+
4775
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4776
+ check_limit(str, opt);
4777
+
4646
4778
  return date__jisx0301(str);
4647
4779
  }
4648
4780
 
4649
4781
  /*
4650
4782
  * call-seq:
4651
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
4783
+ * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4652
4784
  *
4653
4785
  * Creates a new Date object by parsing from a string according to
4654
4786
  * some typical JIS X 0301 formats.
@@ -4658,13 +4790,18 @@ date_s__jisx0301(VALUE klass, VALUE str)
4658
4790
  * For no-era year, legacy format, Heisei is assumed.
4659
4791
  *
4660
4792
  * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
4793
+ *
4794
+ * Raise an ArgumentError when the string length is longer than _limit_.
4795
+ * You can stop this check by passing `limit: nil`, but note that
4796
+ * it may take a long time to parse.
4661
4797
  */
4662
4798
  static VALUE
4663
4799
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4664
4800
  {
4665
- VALUE str, sg;
4801
+ VALUE str, sg, opt;
4666
4802
 
4667
- rb_scan_args(argc, argv, "02", &str, &sg);
4803
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4804
+ if (!NIL_P(opt)) argc--;
4668
4805
 
4669
4806
  switch (argc) {
4670
4807
  case 0:
@@ -4674,7 +4811,11 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4674
4811
  }
4675
4812
 
4676
4813
  {
4677
- VALUE hash = date_s__jisx0301(klass, str);
4814
+ int argc2 = 1;
4815
+ VALUE argv2[2];
4816
+ argv2[0] = str;
4817
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4818
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
4678
4819
  return d_new_by_frags(klass, hash, sg);
4679
4820
  }
4680
4821
  }
@@ -8013,7 +8154,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8013
8154
 
8014
8155
  /*
8015
8156
  * call-seq:
8016
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8157
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
8017
8158
  *
8018
8159
  * Parses the given representation of date and time, and creates a
8019
8160
  * DateTime object.
@@ -8032,13 +8173,18 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8032
8173
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8033
8174
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
8034
8175
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8176
+ *
8177
+ * Raise an ArgumentError when the string length is longer than _limit_.
8178
+ * You can stop this check by passing `limit: nil`, but note that
8179
+ * it may take a long time to parse.
8035
8180
  */
8036
8181
  static VALUE
8037
8182
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8038
8183
  {
8039
- VALUE str, comp, sg;
8184
+ VALUE str, comp, sg, opt;
8040
8185
 
8041
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8186
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8187
+ if (!NIL_P(opt)) argc--;
8042
8188
 
8043
8189
  switch (argc) {
8044
8190
  case 0:
@@ -8050,18 +8196,20 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8050
8196
  }
8051
8197
 
8052
8198
  {
8053
- VALUE argv2[2], hash;
8054
-
8055
- argv2[0] = str;
8056
- argv2[1] = comp;
8057
- hash = date_s__parse(2, argv2, klass);
8199
+ int argc2 = 2;
8200
+ VALUE argv2[3];
8201
+ argv2[0] = str;
8202
+ argv2[1] = comp;
8203
+ argv2[2] = opt;
8204
+ if (!NIL_P(opt)) argc2++;
8205
+ VALUE hash = date_s__parse(argc2, argv2, klass);
8058
8206
  return dt_new_by_frags(klass, hash, sg);
8059
8207
  }
8060
8208
  }
8061
8209
 
8062
8210
  /*
8063
8211
  * call-seq:
8064
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8212
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8065
8213
  *
8066
8214
  * Creates a new DateTime object by parsing from a string according to
8067
8215
  * some typical ISO 8601 formats.
@@ -8072,13 +8220,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8072
8220
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8073
8221
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8074
8222
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8223
+ *
8224
+ * Raise an ArgumentError when the string length is longer than _limit_.
8225
+ * You can stop this check by passing `limit: nil`, but note that
8226
+ * it may take a long time to parse.
8075
8227
  */
8076
8228
  static VALUE
8077
8229
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8078
8230
  {
8079
- VALUE str, sg;
8231
+ VALUE str, sg, opt;
8080
8232
 
8081
- rb_scan_args(argc, argv, "02", &str, &sg);
8233
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8234
+ if (!NIL_P(opt)) argc--;
8082
8235
 
8083
8236
  switch (argc) {
8084
8237
  case 0:
@@ -8088,27 +8241,37 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8088
8241
  }
8089
8242
 
8090
8243
  {
8091
- VALUE hash = date_s__iso8601(klass, str);
8244
+ int argc2 = 1;
8245
+ VALUE argv2[2];
8246
+ argv2[0] = str;
8247
+ argv2[1] = opt;
8248
+ if (!NIL_P(opt)) argc2--;
8249
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
8092
8250
  return dt_new_by_frags(klass, hash, sg);
8093
8251
  }
8094
8252
  }
8095
8253
 
8096
8254
  /*
8097
8255
  * call-seq:
8098
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8256
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8099
8257
  *
8100
8258
  * Creates a new DateTime object by parsing from a string according to
8101
8259
  * some typical RFC 3339 formats.
8102
8260
  *
8103
8261
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8104
8262
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8263
+ *
8264
+ * Raise an ArgumentError when the string length is longer than _limit_.
8265
+ * You can stop this check by passing `limit: nil`, but note that
8266
+ * it may take a long time to parse.
8105
8267
  */
8106
8268
  static VALUE
8107
8269
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8108
8270
  {
8109
- VALUE str, sg;
8271
+ VALUE str, sg, opt;
8110
8272
 
8111
- rb_scan_args(argc, argv, "02", &str, &sg);
8273
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8274
+ if (!NIL_P(opt)) argc--;
8112
8275
 
8113
8276
  switch (argc) {
8114
8277
  case 0:
@@ -8118,27 +8281,37 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8118
8281
  }
8119
8282
 
8120
8283
  {
8121
- VALUE hash = date_s__rfc3339(klass, str);
8284
+ int argc2 = 1;
8285
+ VALUE argv2[2];
8286
+ argv2[0] = str;
8287
+ argv2[1] = opt;
8288
+ if (!NIL_P(opt)) argc2++;
8289
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8122
8290
  return dt_new_by_frags(klass, hash, sg);
8123
8291
  }
8124
8292
  }
8125
8293
 
8126
8294
  /*
8127
8295
  * call-seq:
8128
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8296
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8129
8297
  *
8130
8298
  * Creates a new DateTime object by parsing from a string according to
8131
8299
  * some typical XML Schema formats.
8132
8300
  *
8133
8301
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8134
8302
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8303
+ *
8304
+ * Raise an ArgumentError when the string length is longer than _limit_.
8305
+ * You can stop this check by passing `limit: nil`, but note that
8306
+ * it may take a long time to parse.
8135
8307
  */
8136
8308
  static VALUE
8137
8309
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8138
8310
  {
8139
- VALUE str, sg;
8311
+ VALUE str, sg, opt;
8140
8312
 
8141
- rb_scan_args(argc, argv, "02", &str, &sg);
8313
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8314
+ if (!NIL_P(opt)) argc--;
8142
8315
 
8143
8316
  switch (argc) {
8144
8317
  case 0:
@@ -8148,28 +8321,38 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8148
8321
  }
8149
8322
 
8150
8323
  {
8151
- VALUE hash = date_s__xmlschema(klass, str);
8324
+ int argc2 = 1;
8325
+ VALUE argv2[2];
8326
+ argv2[0] = str;
8327
+ argv2[1] = opt;
8328
+ if (!NIL_P(opt)) argc2++;
8329
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8152
8330
  return dt_new_by_frags(klass, hash, sg);
8153
8331
  }
8154
8332
  }
8155
8333
 
8156
8334
  /*
8157
8335
  * call-seq:
8158
- * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8159
- * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8336
+ * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8337
+ * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8160
8338
  *
8161
8339
  * Creates a new DateTime object by parsing from a string according to
8162
8340
  * some typical RFC 2822 formats.
8163
8341
  *
8164
8342
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8165
8343
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8344
+ *
8345
+ * Raise an ArgumentError when the string length is longer than _limit_.
8346
+ * You can stop this check by passing `limit: nil`, but note that
8347
+ * it may take a long time to parse.
8166
8348
  */
8167
8349
  static VALUE
8168
8350
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8169
8351
  {
8170
- VALUE str, sg;
8352
+ VALUE str, sg, opt;
8171
8353
 
8172
- rb_scan_args(argc, argv, "02", &str, &sg);
8354
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8355
+ if (!NIL_P(opt)) argc--;
8173
8356
 
8174
8357
  switch (argc) {
8175
8358
  case 0:
@@ -8179,7 +8362,12 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8179
8362
  }
8180
8363
 
8181
8364
  {
8182
- VALUE hash = date_s__rfc2822(klass, str);
8365
+ int argc2 = 1;
8366
+ VALUE argv2[2];
8367
+ argv2[0] = str;
8368
+ argv2[1] = opt;
8369
+ if (!NIL_P(opt)) argc2++;
8370
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8183
8371
  return dt_new_by_frags(klass, hash, sg);
8184
8372
  }
8185
8373
  }
@@ -8193,13 +8381,18 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8193
8381
  *
8194
8382
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8195
8383
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8384
+ *
8385
+ * Raise an ArgumentError when the string length is longer than _limit_.
8386
+ * You can stop this check by passing `limit: nil`, but note that
8387
+ * it may take a long time to parse.
8196
8388
  */
8197
8389
  static VALUE
8198
8390
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8199
8391
  {
8200
- VALUE str, sg;
8392
+ VALUE str, sg, opt;
8201
8393
 
8202
- rb_scan_args(argc, argv, "02", &str, &sg);
8394
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8395
+ if (!NIL_P(opt)) argc--;
8203
8396
 
8204
8397
  switch (argc) {
8205
8398
  case 0:
@@ -8209,14 +8402,19 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8209
8402
  }
8210
8403
 
8211
8404
  {
8212
- VALUE hash = date_s__httpdate(klass, str);
8405
+ int argc2 = 1;
8406
+ VALUE argv2[2];
8407
+ argv2[0] = str;
8408
+ argv2[1] = opt;
8409
+ if (!NIL_P(opt)) argc2++;
8410
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
8213
8411
  return dt_new_by_frags(klass, hash, sg);
8214
8412
  }
8215
8413
  }
8216
8414
 
8217
8415
  /*
8218
8416
  * call-seq:
8219
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8417
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8220
8418
  *
8221
8419
  * Creates a new DateTime object by parsing from a string according to
8222
8420
  * some typical JIS X 0301 formats.
@@ -8228,13 +8426,18 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8228
8426
  *
8229
8427
  * DateTime.jisx0301('13.02.03T04:05:06+07:00')
8230
8428
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8429
+ *
8430
+ * Raise an ArgumentError when the string length is longer than _limit_.
8431
+ * You can stop this check by passing `limit: nil`, but note that
8432
+ * it may take a long time to parse.
8231
8433
  */
8232
8434
  static VALUE
8233
8435
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8234
8436
  {
8235
- VALUE str, sg;
8437
+ VALUE str, sg, opt;
8236
8438
 
8237
- rb_scan_args(argc, argv, "02", &str, &sg);
8439
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8440
+ if (!NIL_P(opt)) argc--;
8238
8441
 
8239
8442
  switch (argc) {
8240
8443
  case 0:
@@ -8244,7 +8447,12 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8244
8447
  }
8245
8448
 
8246
8449
  {
8247
- VALUE hash = date_s__jisx0301(klass, str);
8450
+ int argc2 = 1;
8451
+ VALUE argv2[2];
8452
+ argv2[0] = str;
8453
+ argv2[1] = opt;
8454
+ if (!NIL_P(opt)) argc2++;
8455
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8248
8456
  return dt_new_by_frags(klass, hash, sg);
8249
8457
  }
8250
8458
  }
@@ -9403,19 +9611,19 @@ Init_date_core(void)
9403
9611
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9404
9612
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9405
9613
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9406
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9614
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9407
9615
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9408
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9616
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9409
9617
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9410
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9618
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9411
9619
  rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
9412
- rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
9413
- rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
9620
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9621
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9414
9622
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9415
9623
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9416
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9624
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9417
9625
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9418
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9626
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9419
9627
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9420
9628
 
9421
9629
  rb_define_method(cDate, "initialize", date_initialize, -1);
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date
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
  - Tadayoshi Funaba
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-23 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A subclass of Object includes Comparable module for handling dates.
14
14
  email:
15
- -
15
+ -
16
16
  executables: []
17
17
  extensions:
18
18
  - ext/date/extconf.rb
@@ -33,7 +33,7 @@ licenses:
33
33
  - Ruby
34
34
  - BSD-2-Clause
35
35
  metadata: {}
36
- post_install_message:
36
+ post_install_message:
37
37
  rdoc_options: []
38
38
  require_paths:
39
39
  - lib
@@ -48,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.2
52
- signing_key:
51
+ rubygems_version: 3.1.4
52
+ signing_key:
53
53
  specification_version: 4
54
54
  summary: A subclass of Object includes Comparable module for handling dates.
55
55
  test_files: []