From 1ed2959b628d7b2224a81d54a1ccbb62e4f1e3a8 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 25 Aug 2022 22:06:15 +0200 Subject: [PATCH] Prevent noda time splitter from suggesting times with months beyond 12, days beyond 31 --- src/NodaTimeSplitter.php | 6 ++++++ tests/NodaTimeSplitterTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index b31304f..b2d6d42 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -1086,6 +1086,12 @@ final class NodaTimeSplitter { if (!$moda) $moda = NodaTimeSplitter::is_century($datum); if (!$moda) $moda = NodaTimeSplitter::is_decade($datum); + if (!empty($moda)) { + if ((int)$moda[2] > 12 || (int)$moda[3] > 31) { + return []; + } + } + return $moda; } diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 11de382..826658c 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -593,6 +593,16 @@ final class NodaTimeSplitterTest extends TestCase { $output = NodaTimeSplitter::attempt_splitting("Januar-Februar"); self::assertEquals($output, []); + $output = NodaTimeSplitter::attempt_splitting("13.13.2022"); + self::assertEquals($output, []); + $output = NodaTimeSplitter::attempt_splitting("2022-13-13"); + self::assertEquals($output, []); + + $output = NodaTimeSplitter::attempt_splitting("40.10.2022"); + self::assertEquals($output, []); + $output = NodaTimeSplitter::attempt_splitting("2022-10-40"); + self::assertEquals($output, []); + # $output = NodaTimeSplitter::attempt_splitting("Nach 1944-1964"); # self::assertEquals($output, []);