Skip to content

Commit 06ec708

Browse files
authored
Merge pull request #65 from mehmetbeyHZ/master
Check Json types
2 parents 9bfe67e + 6a45a21 commit 06ec708

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
13+
"ext-json": "*"
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^9.3@dev"

src/Common/Common.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public static function mysql_escape($fieldValue)
2020
return (int) $fieldValue;
2121
}
2222

23+
if(self::is_json($fieldValue)){
24+
return $fieldValue;
25+
}
26+
2327
if (!empty($fieldValue) && is_string($fieldValue)) {
2428
return str_replace(
2529
['\\', "\0", "\n", "\r", "'", '"', "\x1a"],
@@ -30,4 +34,12 @@ public static function mysql_escape($fieldValue)
3034

3135
return $fieldValue;
3236
}
37+
38+
protected static function is_json($str): bool
39+
{
40+
if (!is_string($str)){
41+
return false;
42+
}
43+
return json_decode($str, true) !== null;
44+
}
3345
}

0 commit comments

Comments
 (0)