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

Commit 2b5ed84

Browse files
Handled exception when a non-integer question path is requested.
1 parent 55b68c2 commit 2b5ed84

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎src/app/questions/[qid]/page.jsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import QuestionNavigator from "./QuestionNavigator";
33
import { QuestionBody } from "./QuestionBody";
44
import { SolutionWrapper } from "./SolutionWrapper";
55
import { notFound } from "next/navigation";
6+
import isInteger from "@/utils/isInteger";
7+
isInteger;
68

79
export default async function QuestionsPage({ params: { qid } }) {
8-
if (typeofqid!=="bigint") notFound();
10+
if (!isInteger(qid)) notFound();
911

1012
const { data } = await getQuestion(qid);
1113
if (!data) notFound();

‎src/utils/isInteger.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function isInteger(value) {
2+
if (typeof value != "string") return false;
3+
return (
4+
!isNaN(value) &&
5+
parseInt(Number(value)) == value &&
6+
!isNaN(parseInt(value, 10))
7+
);
8+
}

0 commit comments

Comments
(0)

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