Fixes for tests
This commit is contained in:
parent
ed69e36521
commit
3cb71f7ef9
|
|
@ -1222,4 +1222,21 @@ class BaseController extends Controller
|
||||||
{
|
{
|
||||||
return response()->json(['message' => 'Upgrade to a paid plan for this feature.'], 403);
|
return response()->json(['message' => 'Upgrade to a paid plan for this feature.'], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetEncodedFilename
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEncodedFilename(string $filename): string
|
||||||
|
{
|
||||||
|
$ascii_filename = str_replace(['%', '/', '\\'], '', $filename);
|
||||||
|
$ascii_filename = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $ascii_filename);
|
||||||
|
|
||||||
|
$encoded_filename = rawurlencode($filename);
|
||||||
|
|
||||||
|
return "filename=\"$ascii_filename\"; filename*=UTF-8''$encoded_filename";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -815,6 +815,7 @@ class InvoiceController extends BaseController
|
||||||
*/
|
*/
|
||||||
public function downloadPdf($invitation_key)
|
public function downloadPdf($invitation_key)
|
||||||
{
|
{
|
||||||
|
|
||||||
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
||||||
|
|
||||||
if (! $invitation) {
|
if (! $invitation) {
|
||||||
|
|
@ -838,6 +839,7 @@ class InvoiceController extends BaseController
|
||||||
return response()->streamDownload(function () use ($file) {
|
return response()->streamDownload(function () use ($file) {
|
||||||
echo $file;
|
echo $file;
|
||||||
}, $file_name, $headers);
|
}, $file_name, $headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -261,49 +261,49 @@ class BaseModel extends Model
|
||||||
return ctrans("texts.e_invoice"). "_" . $this->numberFormatter().'.'.$extension;
|
return ctrans("texts.e_invoice"). "_" . $this->numberFormatter().'.'.$extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function numberFormatter()
|
|
||||||
{
|
|
||||||
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
|
||||||
|
|
||||||
// Remove control characters
|
|
||||||
$formatted_number = preg_replace('/[\x00-\x1F\x7F]/u', '', $number);
|
|
||||||
|
|
||||||
// Replace slash, backslash, and null byte with underscore
|
|
||||||
$formatted_number = str_replace(['/', '\\', "\0"], '_', $formatted_number);
|
|
||||||
|
|
||||||
// Remove any other characters that are invalid in most filesystems
|
|
||||||
$formatted_number = str_replace(['<', '>', ':', '"', '|', '?', '*'], '', $formatted_number);
|
|
||||||
|
|
||||||
// Replace multiple spaces or underscores with a single underscore
|
|
||||||
$formatted_number = preg_replace('/[\s_]+/', '_', $formatted_number);
|
|
||||||
|
|
||||||
// Trim underscores from start and end
|
|
||||||
$formatted_number = trim($formatted_number, '_');
|
|
||||||
|
|
||||||
// Ensure the filename is not empty
|
|
||||||
if (empty($formatted_number)) {
|
|
||||||
$formatted_number = 'file_' . Str::random(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit the length of the filename (adjust as needed)
|
|
||||||
$formatted_number = mb_substr($formatted_number, 0, 255);
|
|
||||||
|
|
||||||
return $formatted_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public function numberFormatter()
|
// public function numberFormatter()
|
||||||
// {
|
// {
|
||||||
// $number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
// $number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||||
|
|
||||||
// $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
// // Remove control characters
|
||||||
|
// $formatted_number = preg_replace('/[\x00-\x1F\x7F]/u', '', $number);
|
||||||
|
|
||||||
// $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
// // Replace slash, backslash, and null byte with underscore
|
||||||
|
// $formatted_number = str_replace(['/', '\\', "\0"], '_', $formatted_number);
|
||||||
|
|
||||||
// $formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
// // Remove any other characters that are invalid in most filesystems
|
||||||
|
// $formatted_number = str_replace(['<', '>', ':', '"', '|', '?', '*'], '', $formatted_number);
|
||||||
|
|
||||||
// return \Illuminate\Support\Str::ascii($formatted_number);
|
// // Replace multiple spaces or underscores with a single underscore
|
||||||
|
// $formatted_number = preg_replace('/[\s_]+/', '_', $formatted_number);
|
||||||
|
|
||||||
|
// // Trim underscores from start and end
|
||||||
|
// $formatted_number = trim($formatted_number, '_');
|
||||||
|
|
||||||
|
// // Ensure the filename is not empty
|
||||||
|
// if (empty($formatted_number)) {
|
||||||
|
// $formatted_number = 'file_' . Str::random(5);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// // Limit the length of the filename (adjust as needed)
|
||||||
|
// $formatted_number = mb_substr($formatted_number, 0, 255);
|
||||||
|
|
||||||
|
// return $formatted_number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function numberFormatter()
|
||||||
|
{
|
||||||
|
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||||
|
|
||||||
|
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
||||||
|
|
||||||
|
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||||
|
|
||||||
|
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
||||||
|
|
||||||
|
return \Illuminate\Support\Str::ascii($formatted_number);
|
||||||
|
}
|
||||||
|
|
||||||
public function translate_entity()
|
public function translate_entity()
|
||||||
{
|
{
|
||||||
return ctrans('texts.item');
|
return ctrans('texts.item');
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue