Search bar redirects to user feed if you search '@somehandle'

This commit is contained in:
Alessio 2023-08-26 16:50:15 -03:00
parent bde911b56d
commit e3928cc92f
2 changed files with 13 additions and 1 deletions

View File

@ -26,6 +26,11 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
return
}
// Handle "@username"
if search_text[0] == '@' {
http.Redirect(w, r, fmt.Sprintf("/%s", search_text[1:]), 302)
}
c, err := persistence.NewCursorFromSearchQuery(search_text)
if err != nil {
app.error_400_with_message(w, err.Error())

View File

@ -168,7 +168,6 @@ func TestTimelineWithCursorBadNumber(t *testing.T) {
func TestSearchQueryStringRedirect(t *testing.T) {
assert := assert.New(t)
// With a cursor but it sucks
resp := do_request(httptest.NewRequest("GET", "/search?q=asdf", nil))
assert.Equal(resp.StatusCode, 302)
assert.Equal(resp.Header.Get("Location"), "/search/asdf")
@ -209,6 +208,14 @@ func TestSearchWithCursor(t *testing.T) {
assert.Len(cascadia.QueryAll(root, selector(".timeline > .tweet")), 2)
}
func TestSearchRedirectOnUserHandle(t *testing.T) {
assert := assert.New(t)
resp := do_request(httptest.NewRequest("GET", fmt.Sprintf("/search/%s", url.PathEscape("@somebody")), nil))
assert.Equal(resp.StatusCode, 302)
assert.Equal(resp.Header.Get("Location"), "/somebody")
}
// Tweet Detail page
// -----------------