Skip to content

Commit

Permalink
Fix search with bad webfinger handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed May 28, 2019
1 parent 964298d commit c56b774
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions server/controllers/api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ function searchVideoChannels (req: express.Request, res: express.Response) {

// Handle strings like @[email protected]
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)
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/helpers/webfinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c56b774

Please sign in to comment.