Skip to content

Commit

Permalink
[FR DateTimeV2] Stack overflow fix in .NET (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
FARHAD SHAKERIN authored Dec 5, 2022
1 parent c99de05 commit f26b3d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,16 @@ private DateTimeResolutionResult ParseMergedDuration(string text, DateObject ref
var durationExtractor = this.config.DurationExtractor;

// DurationExtractor without parameter will not extract merged duration
var ers = durationExtractor.Extract(text, referenceTime);

// TrimStart() was added to address a bug with french duration expression "depuis ans"
// for which the basecase of the recursive call (i.e., if(ers.Count <= 1))
// would never be reached in which case the stack would overflow.
// The statement if(minStart){...} is meant to find the isolated unit as explained in
// the below comment. However, if there is whitespace before the extacted entity
// (as in " ans") the minStart will be greater than 1 and the Followed Unit regex
// keeps on matching with "ans" and it adds it to ers and it always has
// more than one item in it, hence the recursion never ends.
var ers = durationExtractor.Extract(text.TrimStart(), referenceTime);

// If the duration extractions do not start at 0, check if the input starts with an isolated unit.
// This happens for example with patterns like "next week and 3 days" where "next" is not part of the extraction.
Expand Down
27 changes: 24 additions & 3 deletions Specs/DateTime/French/DateTimeModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3624,7 +3624,7 @@
"End": 67
}
]
},
},
{
"Input": "Je vais rentrer le 4 janvier 2019.",
"NotSupported": "dotnet, javascript, python, java",
Expand Down Expand Up @@ -8694,6 +8694,27 @@
}
]
},
{
"Input": "bonjour la maison n'est plus habitée depuis ans",
"Results": [
{
"Text": "depuis ans",
"Start": 37,
"End": 46,
"TypeName": "datetimeV2.duration",
"Resolution": {
"values": [
{
"timex": "P1Y",
"Mod": "since",
"type": "duration",
"value": "31536000"
}
]
}
}
]
},
{
"Input": "Rechercher les enregistrements durent moins de 2 heures ou plus de 4 jours et pas moins de 30 minutes.",
"NotSupported": "dotnet, javascript, python, java",
Expand Down Expand Up @@ -21372,7 +21393,7 @@
"type": "time",
"value": "08:00:00"
},
{
{
"timex": "T20",
"type": "time",
"value": "20:00:00"
Expand Down Expand Up @@ -21400,7 +21421,7 @@
"type": "time",
"value": "01:00:00"
},
{
{
"timex": "T13",
"type": "time",
"value": "13:00:00"
Expand Down

0 comments on commit f26b3d2

Please sign in to comment.