Skip to content

fix: file name parsing#47

Open
vaguue wants to merge 1 commit into
vercel:mainfrom
vaguue:master
Open

fix: file name parsing#47
vaguue wants to merge 1 commit into
vercel:mainfrom
vaguue:master

Conversation

@vaguue

@vaguue vaguue commented Apr 18, 2023

Copy link
Copy Markdown

Hello! I have observed an unusual behavior with avatar.vercel.sh. The service only provides users with PNG files, even when .svg is specified at the end of the filename. While attempting to find a potential bug, I discovered another minor issue during my code review: if someone requests https://avatar.vercel.sh/username.svg.png, the service responds with an SVG file, which is not quite accurate. I have corrected this issue.

Best regards,
Vaguue.

@vercel

vercel Bot commented Apr 18, 2023

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
avatar ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2023 7:16pm

@vercel-team

Copy link
Copy Markdown

📝 Changed routes:

Commit fe2beb4 (https://avatar-6d1njtsm4.vercel.sh).

@styfle

styfle commented Oct 1, 2024

Copy link
Copy Markdown
Member

const text = url.searchParams.get("text");
const size = Number(url.searchParams.get("size") || "120");
const [username, type] = name?.split(".") || [];
const { 0: username, length, [length - 1]: type }: { length: number, [key: number]: string } = name?.split(".") || [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { 0: username, length, [length - 1]: type }: { length: number, [key: number]: string } = name?.split(".") || [];
const lastDot = name?.lastIndexOf(".");
const username = name?.slice(0, lastDot);
const type = name?.slice(lastDot + 1);

Let's try this so that all the other dots are included in the username.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants