mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-01 14:04:30 +02:00
Sanatize remaining invalid URL characters somehow returned by InfoProviders
This fixes issue #521
This commit is contained in:
parent
4b7d200aa2
commit
12e9497ccf
2 changed files with 64 additions and 2 deletions
|
@ -29,14 +29,24 @@ namespace App\Services\InfoProviderSystem\DTOs;
|
|||
*/
|
||||
class FileDTO
|
||||
{
|
||||
/**
|
||||
* @var string The URL where to get this file
|
||||
*/
|
||||
public readonly string $url;
|
||||
|
||||
/**
|
||||
* @param string $url The URL where to get this file
|
||||
* @param string|null $name Optionally the name of this file
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $url,
|
||||
string $url,
|
||||
public readonly ?string $name = null,
|
||||
) {}
|
||||
) {
|
||||
//Find all occurrences of non URL safe characters and replace them with their URL encoded version.
|
||||
//We only want to replace characters which can not have a valid meaning in a URL (what would break the URL).
|
||||
//Digikey provided some wrong URLs with a ^ in them, which is not a valid URL character. (https://github.com/Part-DB/Part-DB-server/issues/521)
|
||||
$this->url = preg_replace_callback('/[^a-zA-Z0-9_\-.$+!*();\/?:@=&#%]/', fn($matches) => urlencode($matches[0]), $url);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue