Skip to content

Commit 612808a

Browse files
authored
fix: Parse error when user passed contains quotes (#378)
1 parent e6290c9 commit 612808a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules/
55
composer.phar
66
yarn.lock
77
package-lock.json
8+
.vercel
89

910
# Local Configuration
1011
package.json

src/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
try {
3434
// get streak stats for user given in query string
35-
$contributionGraphs = getContributionGraphs($_REQUEST["user"]);
35+
$user = preg_replace("/[^a-zA-Z0-9\-]/", "", $_REQUEST["user"]);
36+
$contributionGraphs = getContributionGraphs($user);
3637
$contributions = getContributionDates($contributionGraphs);
3738
if (isset($_GET["mode"]) && $_GET["mode"] === "weekly") {
3839
$stats = getWeeklyContributionStats($contributions);

src/stats.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ function getContributionYears(string $user): array
191191
}";
192192
$response = fetchGraphQL($query);
193193
// User not found
194-
if (!empty($response->errors) && $response->errors[0]->type === "NOT_FOUND") {
195-
throw new InvalidArgumentException("Could not find a user with that name.", 404);
196-
}
197-
// API Error
198194
if (!empty($response->errors)) {
195+
$type = $response->errors[0]->type ?? "";
196+
if ($type === "NOT_FOUND") {
197+
throw new InvalidArgumentException("Could not find a user with that name.", 404);
198+
}
199+
$message = $response->errors[0]->message ?? "An API error occurred.";
199200
// Other errors that contain a message field
200-
throw new InvalidArgumentException($response->errors[0]->message, 500);
201+
throw new InvalidArgumentException($message, 500);
201202
}
202203
// API did not return data
203204
if (!isset($response->data) && isset($response->message)) {

0 commit comments

Comments
 (0)