Skip to content

Commit ad48da0

Browse files
authored
Merge pull request #2 from SmartBase-SK/feat_sanitize
triv: sanitize all strings from special characters
2 parents 3f00b58 + 8396af7 commit ad48da0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/ObjectSerializer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public static function setDateTimeFormat($format)
2828
self::$dateTimeFormat = $format;
2929
}
3030

31+
public static function removeSpecialCharacters($string)
32+
{
33+
return preg_replace('/[<>`|\\\\]/', '', $string);
34+
}
35+
3136
/**
3237
* Serialize data
3338
*
@@ -39,6 +44,10 @@ public static function setDateTimeFormat($format)
3944
*/
4045
public static function sanitizeForSerialization($data, $type = null, $format = null)
4146
{
47+
if (is_string($data)) {
48+
return self::removeSpecialCharacters($data);
49+
}
50+
4251
if (is_scalar($data) || null === $data) {
4352
return $data;
4453
}

tests/tests.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private function getDirectTransactionPayload(
6969
"variable_symbol" => "123",
7070
]),
7171
"tds_data" => new DirectTransactionTDSData([
72-
"card_holder" => "Janko Hraško",
72+
"card_holder" => "Ja<nko> Hrašk|o",
7373
"email" => "[email protected]",
7474
"billing_address" => $address,
7575
"shipping_address" => $address,
@@ -105,21 +105,21 @@ private function getPaymentPayload(
105105
]);
106106

107107
$userData = new UserData([
108-
"first_name" => "Janko",
109-
"last_name" => "Hrasko",
108+
"first_name" => "|Jan\ko|",
109+
"last_name" => "<Hraško>\\`",
110110
"email" => "[email protected]",
111111
]);
112112

113113
$bankTransfer = new BankTransfer();
114114
$billingAddress = new Address([
115-
"street_name" => "TestStreet",
115+
"street_name" => "<Test|\Street",
116116
"building_number" => "12",
117-
"town_name" => "Town",
117+
"town_name" => "T<ow>n",
118118
"post_code" => "97405",
119119
"country" => "SK",
120120
]);
121121
$shippingAddress = new Address([
122-
"street_name" => "TestStreet",
122+
"street_name" => "T`est| Street",
123123
"building_number" => "12",
124124
"town_name" => "Town",
125125
"post_code" => "97405",

0 commit comments

Comments
 (0)