From 611f7212504b8e8f0b2ae61c84c6f14ac0b7feac Mon Sep 17 00:00:00 2001 From: Trevor Suarez Date: Tue, 5 Mar 2024 22:26:43 -0700 Subject: [PATCH] Fixing Oxford fallback attempting empty search Also clarifying fallback cases in code comments. --- source/oxford/oxford.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/oxford/oxford.go b/source/oxford/oxford.go index 8706c4f..582f813 100644 --- a/source/oxford/oxford.go +++ b/source/oxford/oxford.go @@ -95,6 +95,8 @@ func (a *api) Define(word string) (source.DictionaryResults, error) { if err = validateResponse(word, httpResponse); err != nil { if _, isEmptyResult := err.(*source.EmptyResultError); isEmptyResult { + // Empty (404) result + // Try and automatically fallback return a.apiSearchFallback(word) } @@ -108,6 +110,8 @@ func (a *api) Define(word string) (source.DictionaryResults, error) { } if len(response.Results) < 1 { + // Valid (200), but empty result + // Try and automatically fallback return a.apiSearchFallback(word) } @@ -199,8 +203,8 @@ func (a *api) apiSearchFallback(word string) (source.DictionaryResults, error) { } } - if strings.EqualFold(word, fallbackWord) { - // Prevent matching against the same word + if fallbackWord == "" || strings.EqualFold(word, fallbackWord) { + // Prevent searching for empty or the same word return nil, &source.EmptyResultError{Word: word} }