From cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 May 2019 10:04:07 +0200 Subject: [PATCH] Fix search with bad webfinger handles --- server/controllers/api/search.ts | 14 ++++++++++++-- server/helpers/webfinger.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 534305ba6..9a1e30b83 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts @@ -59,10 +59,12 @@ function searchVideoChannels (req: express.Request, res: express.Response) { // Handle strings like @toto@example.com if (parts.length === 3 && parts[0].length === 0) parts.shift() - const isWebfingerSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1) + const isWebfingerSearch = parts.length === 2 && parts.every(p => p && p.indexOf(' ') === -1) if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) + // @username -> username to search in DB + if (query.search.startsWith('@')) query.search = query.search.replace(/^@/, '') return searchVideoChannelsDB(query, res) } @@ -85,7 +87,15 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean let videoChannel: VideoChannelModel let uri = search - if (isWebfingerSearch) uri = await loadActorUrlOrGetFromWebfinger(search) + if (isWebfingerSearch) { + try { + uri = await loadActorUrlOrGetFromWebfinger(search) + } catch (err) { + logger.warn('Cannot load actor URL or get from webfinger.', { search, err }) + + return res.json({ total: 0, data: [] }) + } + } if (isUserAbleToSearchRemoteURI(res)) { try { diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts index 049808846..d1229e28f 100644 --- a/server/helpers/webfinger.ts +++ b/server/helpers/webfinger.ts @@ -19,7 +19,7 @@ async function loadActorUrlOrGetFromWebfinger (uriArg: string) { const [ name, host ] = uri.split('@') let actor: ActorModel - if (host === WEBSERVER.HOST) { + if (!host || host === WEBSERVER.HOST) { actor = await ActorModel.loadLocalByName(name) } else { actor = await ActorModel.loadByNameAndHost(name, host) -- 2.25.1