Skip to content

Commit

Permalink
fix: prevent handle.invalid mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Feb 29, 2024
1 parent 800f08b commit 65624cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/api/richtext/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,16 @@ export const finalizeRt = async (uid: At.DID, rt: PreliminaryRichText) => {
features: [{ $type: 'app.bsky.richtext.facet#link', uri: segment.uri }],
});
} else if (type === 'mention') {
const handle = segment.handle;

if (handle === 'handle.invalid') {
throw new InvalidHandleError(handle);
}

try {
const response = await agent.rpc.get('com.atproto.identity.resolveHandle', {
params: {
handle: segment.handle,
handle: handle,
},
});

Expand All @@ -457,7 +463,7 @@ export const finalizeRt = async (uid: At.DID, rt: PreliminaryRichText) => {
});
} catch (err) {
if (err instanceof XRPCError && err.error === 'InvalidRequest') {
throw new InvalidHandleError(segment.handle);
throw new InvalidHandleError(handle);
}

throw err;
Expand Down

0 comments on commit 65624cc

Please sign in to comment.