I made a workaround - instead of using Laravel's validation, I am using vanilla PHP - I am replacing every occurence of \r\n with \n, then I check the string length:
if (mb_strlen(str_replace("\r\n", "\n", $request->textarea)) > 50) {
return response()->json("Must be less than 50 characters", 400);
}
@Ligonsker You really need to talk to the infra guys, this will give you more problems than it's worth.
If they want Laravel, they should host it on Linux. There is a reason that most of the web runs on *nix based servers.
I made a workaround - instead of using Laravel's validation, I am using vanilla PHP
@Ligonsker You could instead use middleware that replaces CRLF sequences with just a LF character in the request, before it reaches validation in your form request/controller:
class NormalizeLineEndings
{
public function handle(Request $request, Closure $next, string ...$fields)
{
foreach ($fields as $field) {
if ($request->filled($field)) {
// Replace CRLF with LF
$value = str_replace("\r\n", "\n", $request->input($field));
// Replace lone CR with LF
$value = str_replace("\r", "\n", $request->input($field));
$request->merge([
$field => $value,
]);
}
}
return $next($request);
}
}
You can now validate your fields knowing they only include single LF characters.
@Tray2 I know, I did speak a few times but things move slowly there (a big organization that has been using other stacks and wasn't prepared for that, hopefully that will change)