Skip to content

Commit fe9fa1e

Browse files
author
Wazabii
committed
Data attr improvement
1 parent 55a280a commit fe9fa1e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Utility/Attr.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,29 @@ public function __toString(): string
5454
*/
5555
public function getValue(): string
5656
{
57-
5857
if (!$this->hasBeenEncoded) {
5958
$this->hasBeenEncoded = true;
60-
6159
if ($this->encode) {
60+
// I will rather escape qoutes then encode them in prep is on
6261
$this->value = Encode::value($this->value)->encode(function ($val) {
63-
if ($this->prep) {
64-
$val = Connect::prep($val);
65-
}
6662
return $val;
6763
}, ($this->prep ? ENT_NOQUOTES : ENT_QUOTES))->get();
64+
6865
} else {
69-
if ($this->prep) {
66+
if (is_string($this->value)) {
7067
$this->value = Connect::prep($this->value);
7168
}
7269
}
73-
if (is_array($this->value)) {
74-
$this->value = json_encode($this->value);
70+
if ($this->jsonEncode && is_array($this->value)) {
71+
// If prep is on then escape after json_encode,
72+
// otherwise json encode will possibly escape the escaped value
73+
$this->value = json_encode($this->value, JSON_UNESCAPED_SLASHES);
7574
}
75+
76+
if($this->prep) {
77+
$this->value = Connect::prep($this->value);
78+
}
79+
7680
if ($this->enclose) {
7781
$this->value = "'{$this->value}'";
7882
}

0 commit comments

Comments
 (0)