Repository navigation
Return :invalid_option for bad search and summarize options instead of crashing - #48
Merged
Merged
Conversation
…rbatim, and dates A map or integer in :site, :filetype, or :region raised Protocol.UndefinedError. A truthy non-boolean :verbatim sent verbatim=1. The date regex let a trailing newline and impossible dates through, and :from could be after :to. Validate all of them before the query is built, and parse dates with Date.from_iso8601/1.
…tring A map in :lang raised Protocol.UndefinedError when Req encoded the params.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before
Probe on
origin/main, with%Kagi.Client{session_token: "t"}:The last two reached the network.
verbatim: "false"sentverbatim=1.Problem
AGENTS.mdsays that a public function without a bang returns{:ok, struct}or{:error, %Kagi.Error{}}.Kagi.searchandKagi.summarizeraise on a map in:site,:filetype,:region, or:lang. They also send bad values: any truthy:verbatimturns verbatim on. The date regex accepts"2024-01-01\n","2024-13-45", and a:fromafter:to.After
The same probe on this branch:
No call sends a request. The README now says that
:frommust not be after:to.Cause, design, tests
Cause.
lib/kagi/search.ex:append_filter/3interpolates:siteand:filetypeinto the query, so a map raisesProtocol.UndefinedError.lib/kagi/search.ex:query_params/2passes:regionunchecked to theReqparams.lib/kagi/summary.ex:query_params/2passes:langunchecked astarget_language.lib/kagi/search.ex:validate_date/2used~r/^\d{4}-\d{2}-\d{2}$/.$matches before a trailing newline, and the regex does not check that the date exists.Design.
Kagi.Search.validate_options/1now runs beforebuild_query/2, soappend_filter/3only sees valid values. Onevalidate_string/2checks:site,:filetype, and:region(nil or a non-empty binary).validate_verbatim/1accepts nil or a boolean.parse_date/2parses:fromand:towithDate.from_iso8601/1, andvalidate_date_order/2rejects:fromafter:to. The request still carries the original string. The regex is gone.Kagi.Summary.target_language/1checks:lang(default"EN").lib/kagi/http.ex,CHANGELOG.md, and the version do not change.Tests.
test/kagi/search_test.exs:rejects a :site, :filetype, or :region that is not a non-empty string before any requestrejects a :verbatim that is not a booleanrejects :from with a trailing newline, an impossible date 2024-13-45, and a range where :from is after :toaccepts a valid :from/:to range and sends from_date and to_date unchangedtest/kagi/summary_test.exs:rejects a :lang that is not a non-empty string.A fake adapter sends a message to the test pid, and
refute_receivedproves that no request went out.MIX_ENV=test:mix compile --warnings-as-errors,mix format --check-formatted,mix credo --strict, andmix dialyzerare clean.mix test: 59 passed, 3 excluded (live).