mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/date] Anchor at beginning of numbers
https://hackerone.com/reports/1254844 https://github.com/ruby/date/commit/7ffe25e458
This commit is contained in:
parent
d54a3df2e5
commit
1758eade57
2 changed files with 16 additions and 7 deletions
|
@ -253,6 +253,8 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
|
|||
#define ABBR_DAYS "sun|mon|tue|wed|thu|fri|sat"
|
||||
#define ABBR_MONTHS "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec"
|
||||
|
||||
#define NUMBER "(?<!\\d)\\d"
|
||||
|
||||
#ifdef TIGHT_PARSER
|
||||
#define VALID_DAYS "(?:" DAYS ")" "|(?:tues|wednes|thurs|thur|" ABBR_DAYS ")\\.?"
|
||||
#define VALID_MONTHS "(?:" MONTHS ")" "|(?:sept|" ABBR_MONTHS ")\\.?"
|
||||
|
@ -652,7 +654,7 @@ parse_time(VALUE str, VALUE hash)
|
|||
{
|
||||
static const char pat_source[] =
|
||||
"("
|
||||
"\\d+\\s*"
|
||||
"" NUMBER "+\\s*"
|
||||
"(?:"
|
||||
"(?:"
|
||||
":\\s*\\d+"
|
||||
|
@ -836,7 +838,7 @@ parse_eu(VALUE str, VALUE hash)
|
|||
FPW_COM FPT_COM
|
||||
#endif
|
||||
#ifndef TIGHT_PARSER
|
||||
"('?\\d+)[^-\\d\\s]*"
|
||||
"('?" NUMBER "+)[^-\\d\\s]*"
|
||||
#else
|
||||
"(\\d+)(?:(?:st|nd|rd|th)\\b)?"
|
||||
#endif
|
||||
|
@ -1332,7 +1334,7 @@ parse_vms11(VALUE str, VALUE hash)
|
|||
{
|
||||
static const char pat_source[] =
|
||||
#ifndef TIGHT_PARSER
|
||||
"('?-?\\d+)-(" ABBR_MONTHS ")[^-/.]*"
|
||||
"('?-?" NUMBER "+)-(" ABBR_MONTHS ")[^-/.]*"
|
||||
"-('?-?\\d+)"
|
||||
#else
|
||||
BOS
|
||||
|
@ -1427,7 +1429,7 @@ parse_sla(VALUE str, VALUE hash)
|
|||
{
|
||||
static const char pat_source[] =
|
||||
#ifndef TIGHT_PARSER
|
||||
"('?-?\\d+)/\\s*('?\\d+)(?:\\D\\s*('?-?\\d+))?"
|
||||
"('?-?" NUMBER "+)/\\s*('?\\d+)(?:\\D\\s*('?-?\\d+))?"
|
||||
#else
|
||||
BOS
|
||||
FPW_COM FPT_COM
|
||||
|
@ -1535,7 +1537,7 @@ parse_dot(VALUE str, VALUE hash)
|
|||
{
|
||||
static const char pat_source[] =
|
||||
#ifndef TIGHT_PARSER
|
||||
"('?-?\\d+)\\.\\s*('?\\d+)\\.\\s*('?-?\\d+)"
|
||||
"('?-?" NUMBER "+)\\.\\s*('?\\d+)\\.\\s*('?-?\\d+)"
|
||||
#else
|
||||
BOS
|
||||
FPW_COM FPT_COM
|
||||
|
@ -1695,7 +1697,7 @@ parse_mday(VALUE str, VALUE hash)
|
|||
{
|
||||
static const char pat_source[] =
|
||||
#ifndef TIGHT_PARSER
|
||||
"(\\d+)(st|nd|rd|th)\\b"
|
||||
"(" NUMBER "+)(st|nd|rd|th)\\b"
|
||||
#else
|
||||
BOS
|
||||
FPW_COM FPT_COM
|
||||
|
@ -1933,7 +1935,7 @@ parse_ddd(VALUE str, VALUE hash)
|
|||
#ifdef TIGHT_PARSER
|
||||
BOS
|
||||
#endif
|
||||
"([-+]?)(\\d{2,14})"
|
||||
"([-+]?)(" NUMBER "{2,14})"
|
||||
"(?:"
|
||||
"\\s*"
|
||||
"t?"
|
||||
|
|
|
@ -585,6 +585,13 @@ class TestDateParse < Test::Unit::TestCase
|
|||
assert_equal(5025, h[:offset])
|
||||
end
|
||||
|
||||
def test__parse_too_long_year
|
||||
str = "Jan 1" + "0" * 100_000
|
||||
h = Timeout.timeout(1) {Date._parse(str)}
|
||||
assert_equal(100_000, Math.log10(h[:year]))
|
||||
assert_equal(1, h[:mon])
|
||||
end
|
||||
|
||||
require 'time'
|
||||
|
||||
def test_parse__time
|
||||
|
|
Loading…
Add table
Reference in a new issue