Skip to content

Commit 70ad746

Browse files
committed
str2int
1 parent 742265e commit 70ad746

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

resources/lib/UnityLDAP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function getCustomIDMappings(): array
160160
}
161161
$output_map = [];
162162
foreach ($output as [$uid, $uidNumber_str]) {
163-
$output_map[$uid] = intval($uidNumber_str);
163+
$output_map[$uid] = str2int($uidNumber_str);
164164
}
165165
return $output_map;
166166
}

resources/lib/utils.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use UnityWebPortal\lib\exceptions\ArrayKeyException;
43
use UnityWebPortal\lib\exceptions\EnsureException;
54
use UnityWebPortal\lib\exceptions\EncodingUnknownException;
65
use UnityWebPortal\lib\exceptions\EncodingConversionException;
@@ -83,3 +82,15 @@ function getHyperlink($text, ...$url_components)
8382
$url = getURL(...$url_components);
8483
return "<a href='$url'>$text</a>";
8584
}
85+
86+
/**
87+
* @throws ValueError
88+
*/
89+
function str2int(string $x): int
90+
{
91+
if (is_numeric($x)) {
92+
return intval($x);
93+
} else {
94+
throw new ValueError("not numeric: $x");
95+
}
96+
}

webroot/api/content/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
require_once __DIR__ . "/../../../resources/autoload.php";
88

9-
$CHAR_WRAP = UnityHTTPD::getQueryParameter("line_wrap", false) ?? 80;
9+
$CHAR_WRAP = str2int(UnityHTTPD::getQueryParameter("line_wrap", false) ?? "80");
1010
$content_name = UnityHTTPD::getQueryParameter("content_name");
1111
echo $SQL->getPage($content_name)["content"];

webroot/panel/account.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@
5252
break;
5353
case "delKey":
5454
$keys = $USER->getSSHKeys();
55-
$indexStr = $_POST["delIndex"];
56-
if (!preg_match("/^[0-9]+$/", $indexStr)) {
57-
break;
58-
}
59-
$index = intval($indexStr);
55+
$index = str2int(UnityHTTPD::getPostData("delIndex"));
6056
if ($index >= count($keys)) {
6157
break;
6258
}

0 commit comments

Comments
 (0)