date 3.0.1 → 3.0.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: 9f891e1846f83381a22586299aaa6831910cd9ba63e4a02d6c82db073a4794ba
4
- data.tar.gz: 13bfb909f575de2dc192b95eab90c1808e175327d446ea52d6f137bb3fca99e5
3
+ metadata.gz: d8e8e4c427833f2948ff528def0a31d95b84f1fa977afef755e9fb086ac8c84f
4
+ data.tar.gz: f0f4c810b24a50a1b3b6d766b34099b1dcecaee43bb0bac57c8ea818b2c8626d
5
5
  SHA512:
6
- metadata.gz: 59414c762a7440353fcb0aa66a6b0320b23d15ff2b5557fe950a68655c432af4c5e934e6ac9c78c982db2d0afa90618e554a8dc3f810949bd501f952cd39005b
7
- data.tar.gz: 0f7700b96cb1ad9521aac3eb1b283bdcef38fd6fc6f98e042b011f69751f251e288f0a753148ad61e93d9e8b48bbb629ae9d8d94fcb5aff64366d56209476602
6
+ metadata.gz: 5935548cb2bcf6eb8cb9f46275add4120033355c43c374722bc10be2cb30e90eedfae3333578687fa6a1ba2f10085ca83dea30fa32c3e75f3e347a770a203820
7
+ data.tar.gz: 11fd276dae330c4f6b437e9331b779875ac5ceb05929ab6204b04abcaed107e25421fc6ed32c5b4f58e884972318efef1bf761095a33cc32b1efedf5091ad320
data/ext/date/date_core.c CHANGED
@@ -4322,12 +4322,37 @@ date_s_strptime(int argc, VALUE *argv, VALUE klass)
4322
4322
 
4323
4323
  VALUE date__parse(VALUE str, VALUE comp);
4324
4324
 
4325
+ static size_t
4326
+ get_limit(VALUE opt)
4327
+ {
4328
+ if (!NIL_P(opt)) {
4329
+ VALUE limit = rb_hash_aref(opt, ID2SYM(rb_intern("limit")));
4330
+ if (NIL_P(limit)) return SIZE_MAX;
4331
+ return NUM2SIZET(limit);
4332
+ }
4333
+ return 128;
4334
+ }
4335
+
4336
+ static void
4337
+ check_limit(VALUE str, VALUE opt)
4338
+ {
4339
+ StringValue(str);
4340
+ size_t slen = RSTRING_LEN(str);
4341
+ size_t limit = get_limit(opt);
4342
+ if (slen > limit) {
4343
+ rb_raise(rb_eArgError,
4344
+ "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
4345
+ }
4346
+ }
4347
+
4325
4348
  static VALUE
4326
4349
  date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4327
4350
  {
4328
- VALUE vstr, vcomp, hash;
4351
+ VALUE vstr, vcomp, hash, opt;
4329
4352
 
4330
- rb_scan_args(argc, argv, "11", &vstr, &vcomp);
4353
+ rb_scan_args(argc, argv, "11:", &vstr, &vcomp, &opt);
4354
+ if (!NIL_P(opt)) argc--;
4355
+ check_limit(vstr, opt);
4331
4356
  StringValue(vstr);
4332
4357
  if (!rb_enc_str_asciicompat_p(vstr))
4333
4358
  rb_raise(rb_eArgError,
@@ -4342,7 +4367,7 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4342
4367
 
4343
4368
  /*
4344
4369
  * call-seq:
4345
- * Date._parse(string[, comp=true]) -> hash
4370
+ * Date._parse(string[, comp=true], limit: 128) -> hash
4346
4371
  *
4347
4372
  * Parses the given representation of date and time, and returns a
4348
4373
  * hash of parsed elements. This method does not function as a
@@ -4353,6 +4378,10 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4353
4378
  * it full.
4354
4379
  *
4355
4380
  * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4381
+ *
4382
+ * Raise an ArgumentError when the string length is longer than _limit_.
4383
+ * You can stop this check by passing `limit: nil`, but note that
4384
+ * it may take a long time to parse.
4356
4385
  */
4357
4386
  static VALUE
4358
4387
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4362,7 +4391,7 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4362
4391
 
4363
4392
  /*
4364
4393
  * call-seq:
4365
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]]) -> date
4394
+ * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4366
4395
  *
4367
4396
  * Parses the given representation of date and time, and creates a
4368
4397
  * date object. This method does not function as a validator.
@@ -4374,13 +4403,18 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4374
4403
  * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4375
4404
  * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4376
4405
  * Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
4406
+ *
4407
+ * Raise an ArgumentError when the string length is longer than _limit_.
4408
+ * You can stop this check by passing `limit: nil`, but note that
4409
+ * it may take a long time to parse.
4377
4410
  */
4378
4411
  static VALUE
4379
4412
  date_s_parse(int argc, VALUE *argv, VALUE klass)
4380
4413
  {
4381
- VALUE str, comp, sg;
4414
+ VALUE str, comp, sg, opt;
4382
4415
 
4383
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
4416
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
4417
+ if (!NIL_P(opt)) argc--;
4384
4418
 
4385
4419
  switch (argc) {
4386
4420
  case 0:
@@ -4392,11 +4426,12 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4392
4426
  }
4393
4427
 
4394
4428
  {
4395
- VALUE argv2[2], hash;
4396
-
4397
- argv2[0] = str;
4398
- argv2[1] = comp;
4399
- hash = date_s__parse(2, argv2, klass);
4429
+ int argc2 = 2;
4430
+ VALUE argv2[3];
4431
+ argv2[0] = str;
4432
+ argv2[1] = comp;
4433
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4434
+ VALUE hash = date_s__parse(argc2, argv2, klass);
4400
4435
  return d_new_by_frags(klass, hash, sg);
4401
4436
  }
4402
4437
  }
@@ -4410,19 +4445,28 @@ VALUE date__jisx0301(VALUE);
4410
4445
 
4411
4446
  /*
4412
4447
  * call-seq:
4413
- * Date._iso8601(string) -> hash
4448
+ * Date._iso8601(string, limit: 128) -> hash
4414
4449
  *
4415
4450
  * Returns a hash of parsed elements.
4451
+ *
4452
+ * Raise an ArgumentError when the string length is longer than _limit_.
4453
+ * You can stop this check by passing `limit: nil`, but note that
4454
+ * it may take a long time to parse.
4416
4455
  */
4417
4456
  static VALUE
4418
- date_s__iso8601(VALUE klass, VALUE str)
4457
+ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4419
4458
  {
4459
+ VALUE str, opt;
4460
+
4461
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4462
+ check_limit(str, opt);
4463
+
4420
4464
  return date__iso8601(str);
4421
4465
  }
4422
4466
 
4423
4467
  /*
4424
4468
  * call-seq:
4425
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY]) -> date
4469
+ * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4426
4470
  *
4427
4471
  * Creates a new Date object by parsing from a string according to
4428
4472
  * some typical ISO 8601 formats.
@@ -4430,13 +4474,18 @@ date_s__iso8601(VALUE klass, VALUE str)
4430
4474
  * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4431
4475
  * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4432
4476
  * Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
4477
+ *
4478
+ * Raise an ArgumentError when the string length is longer than _limit_.
4479
+ * You can stop this check by passing `limit: nil`, but note that
4480
+ * it may take a long time to parse.
4433
4481
  */
4434
4482
  static VALUE
4435
4483
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4436
4484
  {
4437
- VALUE str, sg;
4485
+ VALUE str, sg, opt;
4438
4486
 
4439
- rb_scan_args(argc, argv, "02", &str, &sg);
4487
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4488
+ if (!NIL_P(opt)) argc--;
4440
4489
 
4441
4490
  switch (argc) {
4442
4491
  case 0:
@@ -4446,38 +4495,56 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4446
4495
  }
4447
4496
 
4448
4497
  {
4449
- VALUE hash = date_s__iso8601(klass, str);
4498
+ int argc2 = 1;
4499
+ VALUE argv2[2];
4500
+ argv2[0] = str;
4501
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4502
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
4450
4503
  return d_new_by_frags(klass, hash, sg);
4451
4504
  }
4452
4505
  }
4453
4506
 
4454
4507
  /*
4455
4508
  * call-seq:
4456
- * Date._rfc3339(string) -> hash
4509
+ * Date._rfc3339(string, limit: 128) -> hash
4457
4510
  *
4458
4511
  * Returns a hash of parsed elements.
4512
+ *
4513
+ * Raise an ArgumentError when the string length is longer than _limit_.
4514
+ * You can stop this check by passing `limit: nil`, but note that
4515
+ * it may take a long time to parse.
4459
4516
  */
4460
4517
  static VALUE
4461
- date_s__rfc3339(VALUE klass, VALUE str)
4518
+ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4462
4519
  {
4520
+ VALUE str, opt;
4521
+
4522
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4523
+ check_limit(str, opt);
4524
+
4463
4525
  return date__rfc3339(str);
4464
4526
  }
4465
4527
 
4466
4528
  /*
4467
4529
  * call-seq:
4468
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> date
4530
+ * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4469
4531
  *
4470
4532
  * Creates a new Date object by parsing from a string according to
4471
4533
  * some typical RFC 3339 formats.
4472
4534
  *
4473
4535
  * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
4536
+ *
4537
+ * Raise an ArgumentError when the string length is longer than _limit_.
4538
+ * You can stop this check by passing `limit: nil`, but note that
4539
+ * it may take a long time to parse.
4474
4540
  */
4475
4541
  static VALUE
4476
4542
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4477
4543
  {
4478
- VALUE str, sg;
4544
+ VALUE str, sg, opt;
4479
4545
 
4480
- rb_scan_args(argc, argv, "02", &str, &sg);
4546
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4547
+ if (!NIL_P(opt)) argc--;
4481
4548
 
4482
4549
  switch (argc) {
4483
4550
  case 0:
@@ -4487,38 +4554,56 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4487
4554
  }
4488
4555
 
4489
4556
  {
4490
- VALUE hash = date_s__rfc3339(klass, str);
4557
+ int argc2 = 1;
4558
+ VALUE argv2[2];
4559
+ argv2[0] = str;
4560
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4561
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4491
4562
  return d_new_by_frags(klass, hash, sg);
4492
4563
  }
4493
4564
  }
4494
4565
 
4495
4566
  /*
4496
4567
  * call-seq:
4497
- * Date._xmlschema(string) -> hash
4568
+ * Date._xmlschema(string, limit: 128) -> hash
4498
4569
  *
4499
4570
  * Returns a hash of parsed elements.
4571
+ *
4572
+ * Raise an ArgumentError when the string length is longer than _limit_.
4573
+ * You can stop this check by passing `limit: nil`, but note that
4574
+ * it may take a long time to parse.
4500
4575
  */
4501
4576
  static VALUE
4502
- date_s__xmlschema(VALUE klass, VALUE str)
4577
+ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4503
4578
  {
4579
+ VALUE str, opt;
4580
+
4581
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4582
+ check_limit(str, opt);
4583
+
4504
4584
  return date__xmlschema(str);
4505
4585
  }
4506
4586
 
4507
4587
  /*
4508
4588
  * call-seq:
4509
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY]) -> date
4589
+ * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4510
4590
  *
4511
4591
  * Creates a new Date object by parsing from a string according to
4512
4592
  * some typical XML Schema formats.
4513
4593
  *
4514
4594
  * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4595
+ *
4596
+ * Raise an ArgumentError when the string length is longer than _limit_.
4597
+ * You can stop this check by passing `limit: nil`, but note that
4598
+ * it may take a long time to parse.
4515
4599
  */
4516
4600
  static VALUE
4517
4601
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4518
4602
  {
4519
- VALUE str, sg;
4603
+ VALUE str, sg, opt;
4520
4604
 
4521
- rb_scan_args(argc, argv, "02", &str, &sg);
4605
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4606
+ if (!NIL_P(opt)) argc--;
4522
4607
 
4523
4608
  switch (argc) {
4524
4609
  case 0:
@@ -4528,41 +4613,58 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4528
4613
  }
4529
4614
 
4530
4615
  {
4531
- VALUE hash = date_s__xmlschema(klass, str);
4616
+ int argc2 = 1;
4617
+ VALUE argv2[2];
4618
+ argv2[0] = str;
4619
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4620
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4532
4621
  return d_new_by_frags(klass, hash, sg);
4533
4622
  }
4534
4623
  }
4535
4624
 
4536
4625
  /*
4537
4626
  * call-seq:
4538
- * Date._rfc2822(string) -> hash
4539
- * Date._rfc822(string) -> hash
4627
+ * Date._rfc2822(string, limit: 128) -> hash
4628
+ * Date._rfc822(string, limit: 128) -> hash
4540
4629
  *
4541
4630
  * Returns a hash of parsed elements.
4631
+ *
4632
+ * Raise an ArgumentError when the string length is longer than _limit_.
4633
+ * You can stop this check by passing `limit: nil`, but note that
4634
+ * it may take a long time to parse.
4542
4635
  */
4543
4636
  static VALUE
4544
- date_s__rfc2822(VALUE klass, VALUE str)
4637
+ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4545
4638
  {
4639
+ VALUE str, opt;
4640
+
4641
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4642
+ check_limit(str, opt);
4643
+
4546
4644
  return date__rfc2822(str);
4547
4645
  }
4548
4646
 
4549
4647
  /*
4550
4648
  * call-seq:
4551
- * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4552
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> date
4649
+ * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4650
+ * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4553
4651
  *
4554
4652
  * Creates a new Date object by parsing from a string according to
4555
4653
  * some typical RFC 2822 formats.
4556
4654
  *
4557
4655
  * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4558
4656
  * #=> #<Date: 2001-02-03 ...>
4657
+ *
4658
+ * Raise an ArgumentError when the string length is longer than _limit_.
4659
+ * You can stop this check by passing `limit: nil`, but note that
4660
+ * it may take a long time to parse.
4559
4661
  */
4560
4662
  static VALUE
4561
4663
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4562
4664
  {
4563
- VALUE str, sg;
4665
+ VALUE str, sg, opt;
4564
4666
 
4565
- rb_scan_args(argc, argv, "02", &str, &sg);
4667
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4566
4668
 
4567
4669
  switch (argc) {
4568
4670
  case 0:
@@ -4572,39 +4674,56 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4572
4674
  }
4573
4675
 
4574
4676
  {
4575
- VALUE hash = date_s__rfc2822(klass, str);
4677
+ int argc2 = 1;
4678
+ VALUE argv2[2];
4679
+ argv2[0] = str;
4680
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4681
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4576
4682
  return d_new_by_frags(klass, hash, sg);
4577
4683
  }
4578
4684
  }
4579
4685
 
4580
4686
  /*
4581
4687
  * call-seq:
4582
- * Date._httpdate(string) -> hash
4688
+ * Date._httpdate(string, limit: 128) -> hash
4583
4689
  *
4584
4690
  * Returns a hash of parsed elements.
4691
+ *
4692
+ * Raise an ArgumentError when the string length is longer than _limit_.
4693
+ * You can stop this check by passing `limit: nil`, but note that
4694
+ * it may take a long time to parse.
4585
4695
  */
4586
4696
  static VALUE
4587
- date_s__httpdate(VALUE klass, VALUE str)
4697
+ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4588
4698
  {
4699
+ VALUE str, opt;
4700
+
4701
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4702
+ check_limit(str, opt);
4703
+
4589
4704
  return date__httpdate(str);
4590
4705
  }
4591
4706
 
4592
4707
  /*
4593
4708
  * call-seq:
4594
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) -> date
4709
+ * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4595
4710
  *
4596
4711
  * Creates a new Date object by parsing from a string according to
4597
4712
  * some RFC 2616 format.
4598
4713
  *
4599
4714
  * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4600
4715
  * #=> #<Date: 2001-02-03 ...>
4716
+ *
4717
+ * Raise an ArgumentError when the string length is longer than _limit_.
4718
+ * You can stop this check by passing `limit: nil`, but note that
4719
+ * it may take a long time to parse.
4601
4720
  */
4602
4721
  static VALUE
4603
4722
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4604
4723
  {
4605
- VALUE str, sg;
4724
+ VALUE str, sg, opt;
4606
4725
 
4607
- rb_scan_args(argc, argv, "02", &str, &sg);
4726
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4608
4727
 
4609
4728
  switch (argc) {
4610
4729
  case 0:
@@ -4614,26 +4733,39 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4614
4733
  }
4615
4734
 
4616
4735
  {
4617
- VALUE hash = date_s__httpdate(klass, str);
4736
+ int argc2 = 1;
4737
+ VALUE argv2[2];
4738
+ argv2[0] = str;
4739
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4740
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
4618
4741
  return d_new_by_frags(klass, hash, sg);
4619
4742
  }
4620
4743
  }
4621
4744
 
4622
4745
  /*
4623
4746
  * call-seq:
4624
- * Date._jisx0301(string) -> hash
4747
+ * Date._jisx0301(string, limit: 128) -> hash
4625
4748
  *
4626
4749
  * Returns a hash of parsed elements.
4750
+ *
4751
+ * Raise an ArgumentError when the string length is longer than _limit_.
4752
+ * You can stop this check by passing `limit: nil`, but note that
4753
+ * it may take a long time to parse.
4627
4754
  */
4628
4755
  static VALUE
4629
- date_s__jisx0301(VALUE klass, VALUE str)
4756
+ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4630
4757
  {
4758
+ VALUE str, opt;
4759
+
4760
+ rb_scan_args(argc, argv, "1:", &str, &opt);
4761
+ check_limit(str, opt);
4762
+
4631
4763
  return date__jisx0301(str);
4632
4764
  }
4633
4765
 
4634
4766
  /*
4635
4767
  * call-seq:
4636
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY]) -> date
4768
+ * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4637
4769
  *
4638
4770
  * Creates a new Date object by parsing from a string according to
4639
4771
  * some typical JIS X 0301 formats.
@@ -4643,13 +4775,18 @@ date_s__jisx0301(VALUE klass, VALUE str)
4643
4775
  * For no-era year, legacy format, Heisei is assumed.
4644
4776
  *
4645
4777
  * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
4778
+ *
4779
+ * Raise an ArgumentError when the string length is longer than _limit_.
4780
+ * You can stop this check by passing `limit: nil`, but note that
4781
+ * it may take a long time to parse.
4646
4782
  */
4647
4783
  static VALUE
4648
4784
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4649
4785
  {
4650
- VALUE str, sg;
4786
+ VALUE str, sg, opt;
4651
4787
 
4652
- rb_scan_args(argc, argv, "02", &str, &sg);
4788
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
4789
+ if (!NIL_P(opt)) argc--;
4653
4790
 
4654
4791
  switch (argc) {
4655
4792
  case 0:
@@ -4659,7 +4796,11 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4659
4796
  }
4660
4797
 
4661
4798
  {
4662
- VALUE hash = date_s__jisx0301(klass, str);
4799
+ int argc2 = 1;
4800
+ VALUE argv2[2];
4801
+ argv2[0] = str;
4802
+ if (!NIL_P(opt)) argv2[argc2++] = opt;
4803
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
4663
4804
  return d_new_by_frags(klass, hash, sg);
4664
4805
  }
4665
4806
  }
@@ -7998,7 +8139,7 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
7998
8139
 
7999
8140
  /*
8000
8141
  * call-seq:
8001
- * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]]) -> datetime
8142
+ * DateTime.parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) -> datetime
8002
8143
  *
8003
8144
  * Parses the given representation of date and time, and creates a
8004
8145
  * DateTime object. This method does not function as a validator.
@@ -8012,13 +8153,18 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8012
8153
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8013
8154
  * DateTime.parse('3rd Feb 2001 04:05:06 PM')
8014
8155
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8156
+ *
8157
+ * Raise an ArgumentError when the string length is longer than _limit_.
8158
+ * You can stop this check by passing `limit: nil`, but note that
8159
+ * it may take a long time to parse.
8015
8160
  */
8016
8161
  static VALUE
8017
8162
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8018
8163
  {
8019
- VALUE str, comp, sg;
8164
+ VALUE str, comp, sg, opt;
8020
8165
 
8021
- rb_scan_args(argc, argv, "03", &str, &comp, &sg);
8166
+ rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
8167
+ if (!NIL_P(opt)) argc--;
8022
8168
 
8023
8169
  switch (argc) {
8024
8170
  case 0:
@@ -8030,18 +8176,20 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8030
8176
  }
8031
8177
 
8032
8178
  {
8033
- VALUE argv2[2], hash;
8034
-
8035
- argv2[0] = str;
8036
- argv2[1] = comp;
8037
- hash = date_s__parse(2, argv2, klass);
8179
+ int argc2 = 2;
8180
+ VALUE argv2[3];
8181
+ argv2[0] = str;
8182
+ argv2[1] = comp;
8183
+ argv2[2] = opt;
8184
+ if (!NIL_P(opt)) argc2++;
8185
+ VALUE hash = date_s__parse(argc2, argv2, klass);
8038
8186
  return dt_new_by_frags(klass, hash, sg);
8039
8187
  }
8040
8188
  }
8041
8189
 
8042
8190
  /*
8043
8191
  * call-seq:
8044
- * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8192
+ * DateTime.iso8601(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8045
8193
  *
8046
8194
  * Creates a new DateTime object by parsing from a string according to
8047
8195
  * some typical ISO 8601 formats.
@@ -8052,13 +8200,18 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8052
8200
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8053
8201
  * DateTime.iso8601('2001-W05-6T04:05:06+07:00')
8054
8202
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8203
+ *
8204
+ * Raise an ArgumentError when the string length is longer than _limit_.
8205
+ * You can stop this check by passing `limit: nil`, but note that
8206
+ * it may take a long time to parse.
8055
8207
  */
8056
8208
  static VALUE
8057
8209
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8058
8210
  {
8059
- VALUE str, sg;
8211
+ VALUE str, sg, opt;
8060
8212
 
8061
- rb_scan_args(argc, argv, "02", &str, &sg);
8213
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8214
+ if (!NIL_P(opt)) argc--;
8062
8215
 
8063
8216
  switch (argc) {
8064
8217
  case 0:
@@ -8068,27 +8221,37 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8068
8221
  }
8069
8222
 
8070
8223
  {
8071
- VALUE hash = date_s__iso8601(klass, str);
8224
+ int argc2 = 1;
8225
+ VALUE argv2[2];
8226
+ argv2[0] = str;
8227
+ argv2[1] = opt;
8228
+ if (!NIL_P(opt)) argc2--;
8229
+ VALUE hash = date_s__iso8601(argc2, argv2, klass);
8072
8230
  return dt_new_by_frags(klass, hash, sg);
8073
8231
  }
8074
8232
  }
8075
8233
 
8076
8234
  /*
8077
8235
  * call-seq:
8078
- * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8236
+ * DateTime.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8079
8237
  *
8080
8238
  * Creates a new DateTime object by parsing from a string according to
8081
8239
  * some typical RFC 3339 formats.
8082
8240
  *
8083
8241
  * DateTime.rfc3339('2001-02-03T04:05:06+07:00')
8084
8242
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8243
+ *
8244
+ * Raise an ArgumentError when the string length is longer than _limit_.
8245
+ * You can stop this check by passing `limit: nil`, but note that
8246
+ * it may take a long time to parse.
8085
8247
  */
8086
8248
  static VALUE
8087
8249
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8088
8250
  {
8089
- VALUE str, sg;
8251
+ VALUE str, sg, opt;
8090
8252
 
8091
- rb_scan_args(argc, argv, "02", &str, &sg);
8253
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8254
+ if (!NIL_P(opt)) argc--;
8092
8255
 
8093
8256
  switch (argc) {
8094
8257
  case 0:
@@ -8098,27 +8261,37 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8098
8261
  }
8099
8262
 
8100
8263
  {
8101
- VALUE hash = date_s__rfc3339(klass, str);
8264
+ int argc2 = 1;
8265
+ VALUE argv2[2];
8266
+ argv2[0] = str;
8267
+ argv2[1] = opt;
8268
+ if (!NIL_P(opt)) argc2++;
8269
+ VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8102
8270
  return dt_new_by_frags(klass, hash, sg);
8103
8271
  }
8104
8272
  }
8105
8273
 
8106
8274
  /*
8107
8275
  * call-seq:
8108
- * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8276
+ * DateTime.xmlschema(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8109
8277
  *
8110
8278
  * Creates a new DateTime object by parsing from a string according to
8111
8279
  * some typical XML Schema formats.
8112
8280
  *
8113
8281
  * DateTime.xmlschema('2001-02-03T04:05:06+07:00')
8114
8282
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8283
+ *
8284
+ * Raise an ArgumentError when the string length is longer than _limit_.
8285
+ * You can stop this check by passing `limit: nil`, but note that
8286
+ * it may take a long time to parse.
8115
8287
  */
8116
8288
  static VALUE
8117
8289
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8118
8290
  {
8119
- VALUE str, sg;
8291
+ VALUE str, sg, opt;
8120
8292
 
8121
- rb_scan_args(argc, argv, "02", &str, &sg);
8293
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8294
+ if (!NIL_P(opt)) argc--;
8122
8295
 
8123
8296
  switch (argc) {
8124
8297
  case 0:
@@ -8128,28 +8301,38 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8128
8301
  }
8129
8302
 
8130
8303
  {
8131
- VALUE hash = date_s__xmlschema(klass, str);
8304
+ int argc2 = 1;
8305
+ VALUE argv2[2];
8306
+ argv2[0] = str;
8307
+ argv2[1] = opt;
8308
+ if (!NIL_P(opt)) argc2++;
8309
+ VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8132
8310
  return dt_new_by_frags(klass, hash, sg);
8133
8311
  }
8134
8312
  }
8135
8313
 
8136
8314
  /*
8137
8315
  * call-seq:
8138
- * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8139
- * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY]) -> datetime
8316
+ * DateTime.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8317
+ * DateTime.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> datetime
8140
8318
  *
8141
8319
  * Creates a new DateTime object by parsing from a string according to
8142
8320
  * some typical RFC 2822 formats.
8143
8321
  *
8144
8322
  * DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700')
8145
8323
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8324
+ *
8325
+ * Raise an ArgumentError when the string length is longer than _limit_.
8326
+ * You can stop this check by passing `limit: nil`, but note that
8327
+ * it may take a long time to parse.
8146
8328
  */
8147
8329
  static VALUE
8148
8330
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8149
8331
  {
8150
- VALUE str, sg;
8332
+ VALUE str, sg, opt;
8151
8333
 
8152
- rb_scan_args(argc, argv, "02", &str, &sg);
8334
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8335
+ if (!NIL_P(opt)) argc--;
8153
8336
 
8154
8337
  switch (argc) {
8155
8338
  case 0:
@@ -8159,7 +8342,12 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8159
8342
  }
8160
8343
 
8161
8344
  {
8162
- VALUE hash = date_s__rfc2822(klass, str);
8345
+ int argc2 = 1;
8346
+ VALUE argv2[2];
8347
+ argv2[0] = str;
8348
+ argv2[1] = opt;
8349
+ if (!NIL_P(opt)) argc2++;
8350
+ VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8163
8351
  return dt_new_by_frags(klass, hash, sg);
8164
8352
  }
8165
8353
  }
@@ -8173,13 +8361,18 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8173
8361
  *
8174
8362
  * DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
8175
8363
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8364
+ *
8365
+ * Raise an ArgumentError when the string length is longer than _limit_.
8366
+ * You can stop this check by passing `limit: nil`, but note that
8367
+ * it may take a long time to parse.
8176
8368
  */
8177
8369
  static VALUE
8178
8370
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8179
8371
  {
8180
- VALUE str, sg;
8372
+ VALUE str, sg, opt;
8181
8373
 
8182
- rb_scan_args(argc, argv, "02", &str, &sg);
8374
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8375
+ if (!NIL_P(opt)) argc--;
8183
8376
 
8184
8377
  switch (argc) {
8185
8378
  case 0:
@@ -8189,14 +8382,19 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8189
8382
  }
8190
8383
 
8191
8384
  {
8192
- VALUE hash = date_s__httpdate(klass, str);
8385
+ int argc2 = 1;
8386
+ VALUE argv2[2];
8387
+ argv2[0] = str;
8388
+ argv2[1] = opt;
8389
+ if (!NIL_P(opt)) argc2++;
8390
+ VALUE hash = date_s__httpdate(argc2, argv2, klass);
8193
8391
  return dt_new_by_frags(klass, hash, sg);
8194
8392
  }
8195
8393
  }
8196
8394
 
8197
8395
  /*
8198
8396
  * call-seq:
8199
- * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY]) -> datetime
8397
+ * DateTime.jisx0301(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> datetime
8200
8398
  *
8201
8399
  * Creates a new DateTime object by parsing from a string according to
8202
8400
  * some typical JIS X 0301 formats.
@@ -8208,13 +8406,18 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8208
8406
  *
8209
8407
  * DateTime.jisx0301('13.02.03T04:05:06+07:00')
8210
8408
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8409
+ *
8410
+ * Raise an ArgumentError when the string length is longer than _limit_.
8411
+ * You can stop this check by passing `limit: nil`, but note that
8412
+ * it may take a long time to parse.
8211
8413
  */
8212
8414
  static VALUE
8213
8415
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8214
8416
  {
8215
- VALUE str, sg;
8417
+ VALUE str, sg, opt;
8216
8418
 
8217
- rb_scan_args(argc, argv, "02", &str, &sg);
8419
+ rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
8420
+ if (!NIL_P(opt)) argc--;
8218
8421
 
8219
8422
  switch (argc) {
8220
8423
  case 0:
@@ -8224,7 +8427,12 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8224
8427
  }
8225
8428
 
8226
8429
  {
8227
- VALUE hash = date_s__jisx0301(klass, str);
8430
+ int argc2 = 1;
8431
+ VALUE argv2[2];
8432
+ argv2[0] = str;
8433
+ argv2[1] = opt;
8434
+ if (!NIL_P(opt)) argc2++;
8435
+ VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8228
8436
  return dt_new_by_frags(klass, hash, sg);
8229
8437
  }
8230
8438
  }
@@ -9383,19 +9591,19 @@ Init_date_core(void)
9383
9591
  rb_define_singleton_method(cDate, "strptime", date_s_strptime, -1);
9384
9592
  rb_define_singleton_method(cDate, "_parse", date_s__parse, -1);
9385
9593
  rb_define_singleton_method(cDate, "parse", date_s_parse, -1);
9386
- rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, 1);
9594
+ rb_define_singleton_method(cDate, "_iso8601", date_s__iso8601, -1);
9387
9595
  rb_define_singleton_method(cDate, "iso8601", date_s_iso8601, -1);
9388
- rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, 1);
9596
+ rb_define_singleton_method(cDate, "_rfc3339", date_s__rfc3339, -1);
9389
9597
  rb_define_singleton_method(cDate, "rfc3339", date_s_rfc3339, -1);
9390
- rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, 1);
9598
+ rb_define_singleton_method(cDate, "_xmlschema", date_s__xmlschema, -1);
9391
9599
  rb_define_singleton_method(cDate, "xmlschema", date_s_xmlschema, -1);
9392
- rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, 1);
9393
- rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, 1);
9600
+ rb_define_singleton_method(cDate, "_rfc2822", date_s__rfc2822, -1);
9601
+ rb_define_singleton_method(cDate, "_rfc822", date_s__rfc2822, -1);
9394
9602
  rb_define_singleton_method(cDate, "rfc2822", date_s_rfc2822, -1);
9395
9603
  rb_define_singleton_method(cDate, "rfc822", date_s_rfc2822, -1);
9396
- rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, 1);
9604
+ rb_define_singleton_method(cDate, "_httpdate", date_s__httpdate, -1);
9397
9605
  rb_define_singleton_method(cDate, "httpdate", date_s_httpdate, -1);
9398
- rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9606
+ rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, -1);
9399
9607
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9400
9608
 
9401
9609
  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.0.1
4
+ version: 3.0.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-06-19 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
@@ -32,7 +32,7 @@ homepage: https://github.com/ruby/date
32
32
  licenses:
33
33
  - BSD-2-Clause
34
34
  metadata: {}
35
- post_install_message:
35
+ post_install_message:
36
36
  rdoc_options: []
37
37
  require_paths:
38
38
  - lib
@@ -47,8 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.2.0.pre1
51
- signing_key:
50
+ rubygems_version: 3.1.4
51
+ signing_key:
52
52
  specification_version: 4
53
53
  summary: A subclass of Object includes Comparable module for handling dates.
54
54
  test_files: []