From fb33238f72212a54224fbee00d6f270ebebc84f3 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 31 Dec 2019 23:44:28 -0500 Subject: [PATCH] fix error in search parser when using 0 for day/month, fix link to search syntax page on search form --- lib/philomena_web/templates/search/_form.html.slime | 2 +- lib/search/date_parser.ex | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/philomena_web/templates/search/_form.html.slime b/lib/philomena_web/templates/search/_form.html.slime index b5d78f5b..18348c2b 100644 --- a/lib/philomena_web/templates/search/_form.html.slime +++ b/lib/philomena_web/templates/search/_form.html.slime @@ -37,7 +37,7 @@ h1 Search a data-search-add="my:watched" data-search-show-help=" " My watched tags .flex__right a href="#" data-click-toggle="#js-search-tags" Quick tags - a href="/search/syntax" Help + a href="/pages/search_syntax" Help .block__content .hidden.walloftext data-search-help="numeric" diff --git a/lib/search/date_parser.ex b/lib/search/date_parser.ex index df2be451..a7034d63 100644 --- a/lib/search/date_parser.ex +++ b/lib/search/date_parser.ex @@ -1,6 +1,8 @@ defmodule Search.DateParser do import NimbleParsec + defp to_int(input), do: Search.Helpers.to_int(input) + defp build_datetime(naive, tz_off, tz_hour, tz_minute) do tz_hour = tz_hour @@ -103,9 +105,14 @@ defmodule Search.DateParser do choice([string(" "), string("\t"), string("\n"), string("\r"), string("\v"), string("\f")]) |> ignore() + pos_2dig_int = + ascii_char('123456789') + |> ascii_char('0123456789') + |> reduce(:to_int) + year = integer(4) - month = integer(2) - day = integer(2) + month = pos_2dig_int + day = pos_2dig_int hour = integer(2) minute = integer(2) @@ -186,4 +193,4 @@ defmodule Search.DateParser do |> label("a RFC3339 datetime fragment, like `2019-01-01', or relative date, like `3 days ago'") defparsec :parse, date -end \ No newline at end of file +end