Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: validate top-langs query #2761

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

Open
manhhungpc wants to merge 1 commit into anuraghazra:master
base: master
Choose a base branch
Loading
from manhhungpc:validate-top-lang-query

Conversation

@manhhungpc
Copy link

@manhhungpc manhhungpc commented May 31, 2023
edited
Loading

This commit validate the query to make sure not display NaN percentage and throw an error when have an invalid query. For example: /api/top-langs?&username=manhhungpc&theme=dark&size_weight=0&count_weight=1langs_count=10&layout=compact where &count_weight=1langs_count=10 is invalid query. See (#2735) for more details

Copy link

vercel bot commented May 31, 2023

@manhhungpc is attempting to deploy a commit to the github readme stats Team on Vercel.

A member of the Team first needs to authorize it.

@manhhungpc manhhungpc changed the title (削除) fix: validate top-langs query (#2735) (削除ここまで) (追記) fix: validate top-langs query (追記ここまで) Jun 2, 2023
Comment on lines +63 to +68
for (let [_, value] of Object.entries(req.query)) {
queriesName.map((name) => {
if (value.toString().includes(name))
return res.send(renderError("Something went wrong", "Invalid query"));
});
}
Copy link
Owner

@anuraghazra anuraghazra Jul 1, 2023

Choose a reason for hiding this comment

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

Thanks for the PR @manhhungpc.

It will be better to stay a bit loose than this strict req.query checking. Right now even if people add an extraneous query or do a simple mistake this will throw error for the whole card.
Not to mention it might also have a negative side effect - Imagine later down the line we remove or deprecate a query param, now people might not update the URL even if the query param is deprecated but this code will throw error and users will have no idea why it's failing.

Instead it will be better if we don't throw instead if a query param is malformed we just ditch that param's value or default it to something sensible.

Eg for the count_weight if its NaN we just disregard it.

Copy link
Collaborator

@rickstaa rickstaa Jul 3, 2023

Choose a reason for hiding this comment

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

Thanks for the PR @manhhungpc.

It will be better to stay a bit loose than this strict req.query checking. Right now even if people add an extraneous query or do a simple mistake this will throw error for the whole card. Not to mention it might also have a negative side effect - Imagine later down the line we remove or deprecate a query param, now people might not update the URL even if the query param is deprecated but this code will throw error and users will have no idea why it's failing.

Instead it will be better if we don't throw instead if a query param is malformed we just ditch that param's value or default it to something sensible.

Eg for the count_weight if its NaN we just disregard it.

@manhhungpc I agree with @anuraghazra. Let's close this pr for now. Free free to create a new pull request that fixes the NaN bug explained in #2735 by ditching the incorrect parameter value and reverting back to default.

manhhungpc reacted with heart emoji
Copy link
Collaborator

@rickstaa rickstaa Jul 3, 2023
edited
Loading

Choose a reason for hiding this comment

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

@manhhungpc on second. To keep a history of the decision above, maybe let's keep this open and apply the changes to this pull request.

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

Reviewers

@rickstaa rickstaa rickstaa left review comments

@anuraghazra anuraghazra anuraghazra left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

lang-card Issues related to the language card.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /