Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: file name parsing #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix: file name parsing #47

wants to merge 1 commit into from

Conversation

vaguue
Copy link

@vaguue vaguue commented Apr 18, 2023

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
Copy link

vercel bot commented Apr 18, 2023

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

📝 Changed routes:

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

@@ -11,7 +11,7 @@ export default async function (req: NextRequest) {
const name = url.searchParams.get("name");
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
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