Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Support\Traits\Macroable;
use JsonException;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
Expand Down Expand Up @@ -546,17 +545,7 @@ public static function isJson($value)
return false;
}

if (function_exists('json_validate')) {
return json_validate($value, 512);
}

try {
json_decode($value, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return false;
}

return true;
return json_validate($value, 512);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we remove the 512 here? That's the default and we don't include it in the changes in ValidatesAttributes.php in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd agree. I imagine a PR for this would get accepted.

}

/**
Expand Down Expand Up @@ -906,17 +895,7 @@ public static function numbers($value)
*/
public static function padBoth($value, $length, $pad = ' ')
{
if (function_exists('mb_str_pad')) {
return mb_str_pad($value, $length, $pad, STR_PAD_BOTH);
}

$short = max(0, $length - mb_strlen($value));
$shortLeft = floor($short / 2);
$shortRight = ceil($short / 2);

return mb_substr(str_repeat($pad, $shortLeft), 0, $shortLeft).
$value.
mb_substr(str_repeat($pad, $shortRight), 0, $shortRight);
return mb_str_pad($value, $length, $pad, STR_PAD_BOTH);
}

/**
Expand All @@ -929,13 +908,7 @@ public static function padBoth($value, $length, $pad = ' ')
*/
public static function padLeft($value, $length, $pad = ' ')
{
if (function_exists('mb_str_pad')) {
return mb_str_pad($value, $length, $pad, STR_PAD_LEFT);
}

$short = max(0, $length - mb_strlen($value));

return mb_substr(str_repeat($pad, $short), 0, $short).$value;
return mb_str_pad($value, $length, $pad, STR_PAD_LEFT);
}

/**
Expand All @@ -948,13 +921,7 @@ public static function padLeft($value, $length, $pad = ' ')
*/
public static function padRight($value, $length, $pad = ' ')
{
if (function_exists('mb_str_pad')) {
return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT);
}

$short = max(0, $length - mb_strlen($value));

return $value.mb_substr(str_repeat($pad, $short), 0, $short);
return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT);
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1526,13 +1526,7 @@ public function validateJson($attribute, $value)
return false;
}

if (function_exists('json_validate')) {
return json_validate($value);
}

json_decode($value);

return json_last_error() === JSON_ERROR_NONE;
return json_validate($value);
}

/**
Expand Down
Loading