Use rawurlencode instead of urlencode to sanatize URL-unsafe characters returned by the info providers.

This commit is contained in:
Jan Böhmer 2024-02-24 23:58:27 +01:00
parent 12e9497ccf
commit a5d184baef
2 changed files with 2 additions and 2 deletions

View file

@ -45,7 +45,7 @@ class FileDTO
//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);
$this->url = preg_replace_callback('/[^a-zA-Z0-9_\-.$+!*();\/?:@=&#%]/', fn($matches) => rawurlencode($matches[0]), $url);
}

View file

@ -36,7 +36,7 @@ class FileDTOTest extends TestCase
//Remaining URL unsafe characters must be escaped
["test%5Ese", "test^se"],
["test+se", "test se"],
["test%20se", "test se"],
["test%7Cse", "test|se"],
];
}