From a5d184baef368e3e575b0adc10178e1a05a1bd3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 24 Feb 2024 23:58:27 +0100 Subject: [PATCH] Use rawurlencode instead of urlencode to sanatize URL-unsafe characters returned by the info providers. --- src/Services/InfoProviderSystem/DTOs/FileDTO.php | 2 +- tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/InfoProviderSystem/DTOs/FileDTO.php b/src/Services/InfoProviderSystem/DTOs/FileDTO.php index d5ba7fe2..96dd1838 100644 --- a/src/Services/InfoProviderSystem/DTOs/FileDTO.php +++ b/src/Services/InfoProviderSystem/DTOs/FileDTO.php @@ -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); } diff --git a/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php b/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php index 3f0deafd..8ec454e7 100644 --- a/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php +++ b/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php @@ -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"], ]; }