rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -914,6 +914,12 @@ class wfUserIPRange {
return false;
}
private static function repeatString($string, $count) {
if ($count <= 0)
return '';
return str_repeat($string, $count);
}
/**
* Expand a compressed printable range representation of an IPv6 address.
*
@@ -930,7 +936,7 @@ class wfUserIPRange {
}
$dbl_colon_pos = strpos($ip_range, '::');
if ($dbl_colon_pos !== false) {
$ip_range = str_replace('::', str_repeat(':0000',
$ip_range = str_replace('::', self::repeatString(':0000',
(($dbl_colon_pos === 0 || $dbl_colon_pos === strlen($ip_range) - 2) ? 9 : 8) - $colon_count) . ':', $ip_range);
$ip_range = trim($ip_range, ':');
}
@@ -1269,7 +1275,7 @@ class wfRequestModel extends wfModel {
* @param $actionData
* @return mixed|string|void
*/
public static function serializeActionData($actionData) {
public static function serializeActionData($actionData, $optionalKeys = array(), $maxLength = 65535) {
if (is_array($actionData)) {
foreach (self::$actionDataEncodedParams as $key) {
if (array_key_exists($key, $actionData)) {
@@ -1277,7 +1283,31 @@ class wfRequestModel extends wfModel {
}
}
}
return json_encode($actionData);
do {
$serialized = json_encode($actionData, JSON_UNESCAPED_SLASHES);
$length = strlen($serialized);
if ($length <= $maxLength)
return $serialized;
$excess = $length - $maxLength;
$truncated = false;
foreach ($optionalKeys as $key) {
if (array_key_exists($key, $actionData)) {
$fieldValue = $actionData[$key];
$fieldLength = strlen($fieldValue);
$truncatedLength = min($fieldLength, $excess);
$truncated = true;
if ($truncatedLength > 0) {
$actionData[$key] = substr($fieldValue, 0, -$truncatedLength);
$excess -= $truncatedLength;
}
else {
unset($actionData[$key]);
break;
}
}
}
} while ($truncated);
return null;
}
/**