Skip to content

Commit 8cdd413

Browse files
Merge branch 'release/9.0.4'
2 parents b252800 + 5d2d028 commit 8cdd413

File tree

6 files changed

+74
-50
lines changed

6 files changed

+74
-50
lines changed

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Description: Customisable email and webhook notifications with powerful developer friendly API for custom triggers and notifications. Send alerts easily.
55
* Author: BracketSpace
66
* Author URI: https://bracketspace.com
7-
* Version: 9.0.3
7+
* Version: 9.0.4
88
* Requires PHP: 7.4
99
* Requires at least: 5.8
1010
* License: GPL3

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: notification, bracketspace, Kubitomakita, tomaszadamowicz, insejn,
33
Tags: notification, notify, alert, email, mail, webhook, API, developer, framework
44
Requires at least: 4.9
55
Tested up to: 6.6
6-
Stable tag: 9.0.3
6+
Stable tag: 9.0.4
77
Requires PHP: 7.4
88
License: GPLv3
99
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -297,6 +297,9 @@ Yes! We're offering a [custom plugin development](https://bracketspace.com/custo
297297

298298
== Changelog ==
299299

300+
= 9.0.4 =
301+
* [Fixed] Fix issues with invalid JSON of Notification in wp_posts table.
302+
300303
= 9.0.3 =
301304
* [Fixed] No license activated in v8 being displayed in the admin.
302305

src/Database/NotificationDatabaseService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public static function upsert(Notification $notification)
223223
/**
224224
* @todo Remove backward compatibility content save.
225225
*/
226-
'post_content' => $notification->to('json'),
226+
'post_content' => wp_slash($notification->to('json')),
227227
'post_status' => $notification->isEnabled() ? 'publish' : 'draft',
228228
'post_type' => 'notification',
229229
]

src/Repository/Converter/JsonConverter.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function from($data): Notification
3636
throw $invalidException;
3737
}
3838

39+
$data = $this->escapeQuotes($data);
40+
3941
$jsonData = json_decode($data, true);
4042

4143
if (json_last_error() !== JSON_ERROR_NONE) {
@@ -69,4 +71,40 @@ public function to(Notification $notification, array $config = [])
6971

7072
return wp_json_encode($data, $jsonOptions);
7173
}
74+
75+
/**
76+
* Find unescaped quotes n JSON and escapes them.
77+
*
78+
* `wp_insert_post` considers `post_content` to be escaped, so before saving
79+
* data it passes content through `wp_unslash` function. Because of that old
80+
* notifications might have unescaped quotes in content which will cause
81+
* JSON decoding errors.
82+
*
83+
* @see https://core.trac.wordpress.org/ticket/54601
84+
*
85+
* @param string $originalData
86+
* @return string
87+
*/
88+
private function escapeQuotes(string $originalData): string
89+
{
90+
$data = preg_replace_callback(
91+
'/
92+
".+?": # key
93+
\s+ # white characters after key
94+
"( # string value start quote
95+
.+? # any value content
96+
[^\\\\]" # quote within value which is not escaped
97+
.+? # any value content
98+
)" # string value end quote
99+
,? # there might be comma after value
100+
\n # formatted JSON will always have new line after value
101+
/x',
102+
static function ($matches) {
103+
return str_replace($matches[1], str_replace('"', '\\"', $matches[1]), $matches[0]);
104+
},
105+
$originalData
106+
);
107+
108+
return is_string($data) ? $data : $originalData;
109+
}
72110
}

yarn.lock

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,23 +1389,7 @@
13891389
"@types/node" "*"
13901390
"@types/responselike" "^1.0.0"
13911391

1392-
"@types/eslint-scope@^3.7.3":
1393-
version "3.7.7"
1394-
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5"
1395-
integrity sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==
1396-
dependencies:
1397-
"@types/eslint" "*"
1398-
"@types/estree" "*"
1399-
1400-
"@types/eslint@*":
1401-
version "8.56.9"
1402-
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.9.tgz#403e9ced04a34e63f1c383c5b8ee1a94442c8cc4"
1403-
integrity sha512-W4W3KcqzjJ0sHg2vAq9vfml6OhsJ53TcUjUqfzzZf/EChUtwspszj/S0pzMxnfRcO55/iGq47dscXw71Fxc4Zg==
1404-
dependencies:
1405-
"@types/estree" "*"
1406-
"@types/json-schema" "*"
1407-
1408-
"@types/estree@*", "@types/estree@^1.0.5":
1392+
"@types/estree@^1.0.5":
14091393
version "1.0.5"
14101394
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
14111395
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==
@@ -1423,7 +1407,7 @@
14231407
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz#b979ebad3919799c979b17c72621c0bc0a31c6c4"
14241408
integrity sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==
14251409

1426-
"@types/json-schema@*", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
1410+
"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
14271411
version "7.0.15"
14281412
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
14291413
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
@@ -1857,10 +1841,10 @@
18571841
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
18581842
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
18591843

1860-
acorn-import-assertions@^1.9.0:
1861-
version "1.9.0"
1862-
resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz#507276249d684797c84e0734ef84860334cfb1ac"
1863-
integrity sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==
1844+
acorn-import-attributes@^1.9.5:
1845+
version "1.9.5"
1846+
resolved "https://registry.yarnpkg.com/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz#7eb1557b1ba05ef18b5ed0ec67591bfab04688ef"
1847+
integrity sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==
18641848

18651849
acorn-jsx@^5.3.2:
18661850
version "5.3.2"
@@ -2287,7 +2271,7 @@ brace-expansion@^1.1.7:
22872271
balanced-match "^1.0.0"
22882272
concat-map "0.0.1"
22892273

2290-
braces@^3.0.2, braces@~3.0.2:
2274+
braces@^3.0.3, braces@~3.0.2:
22912275
version "3.0.3"
22922276
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
22932277
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
@@ -3217,10 +3201,10 @@ enhanced-resolve@^0.9.1:
32173201
memory-fs "^0.2.0"
32183202
tapable "^0.1.8"
32193203

3220-
enhanced-resolve@^5.16.0:
3221-
version "5.16.0"
3222-
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.16.0.tgz#65ec88778083056cb32487faa9aef82ed0864787"
3223-
integrity sha512-O+QWCviPNSSLAD9Ucn8Awv+poAkqn3T1XY5/N7kR7rQO9yfSGWkYZDwpJ+iKF7B8rxaQKWngSqACpgzeapSyoA==
3204+
enhanced-resolve@^5.17.1:
3205+
version "5.17.1"
3206+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15"
3207+
integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==
32243208
dependencies:
32253209
graceful-fs "^4.2.4"
32263210
tapable "^2.2.0"
@@ -3805,9 +3789,9 @@ fast-levenshtein@^2.0.6:
38053789
integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==
38063790

38073791
fast-xml-parser@^4.1.3:
3808-
version "4.3.6"
3809-
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.3.6.tgz#190f9d99097f0c8f2d3a0e681a10404afca052ff"
3810-
integrity sha512-M2SovcRxD4+vC493Uc2GZVcZaj66CCJhWurC4viynVSTvrpErCShNcDz1lAho6n9REQKvL/ll4A4/fw6Y9z8nw==
3792+
version "4.5.0"
3793+
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.5.0.tgz#2882b7d01a6825dfdf909638f2de0256351def37"
3794+
integrity sha512-/PlTQCI96+fZMAOLMZK4CWG1ItCbfZ/0jx7UIJFChPNrx7tcEgerUgWbeieCM9MfHInUDyK8DWYZ+YrywDJuTg==
38113795
dependencies:
38123796
strnum "^1.0.5"
38133797

@@ -5372,11 +5356,11 @@ merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
53725356
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
53735357

53745358
micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5:
5375-
version "4.0.5"
5376-
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6"
5377-
integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==
5359+
version "4.0.8"
5360+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202"
5361+
integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==
53785362
dependencies:
5379-
braces "^3.0.2"
5363+
braces "^3.0.3"
53805364
picomatch "^2.3.1"
53815365

53825366
@@ -7741,20 +7725,19 @@ webpack-sources@^3.2.2, webpack-sources@^3.2.3:
77417725
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
77427726

77437727
webpack@5:
7744-
version "5.91.0"
7745-
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.91.0.tgz#ffa92c1c618d18c878f06892bbdc3373c71a01d9"
7746-
integrity sha512-rzVwlLeBWHJbmgTC/8TvAcu5vpJNII+MelQpylD4jNERPwpBJOE2lEcko1zJX3QJeLjTTAnQxn/OJ8bjDzVQaw==
7728+
version "5.95.0"
7729+
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.95.0.tgz#8fd8c454fa60dad186fbe36c400a55848307b4c0"
7730+
integrity sha512-2t3XstrKULz41MNMBF+cJ97TyHdyQ8HCt//pqErqDvNjU9YQBnZxIHa11VXsi7F3mb5/aO2tuDxdeTPdU7xu9Q==
77477731
dependencies:
7748-
"@types/eslint-scope" "^3.7.3"
77497732
"@types/estree" "^1.0.5"
77507733
"@webassemblyjs/ast" "^1.12.1"
77517734
"@webassemblyjs/wasm-edit" "^1.12.1"
77527735
"@webassemblyjs/wasm-parser" "^1.12.1"
77537736
acorn "^8.7.1"
7754-
acorn-import-assertions "^1.9.0"
7737+
acorn-import-attributes "^1.9.5"
77557738
browserslist "^4.21.10"
77567739
chrome-trace-event "^1.0.2"
7757-
enhanced-resolve "^5.16.0"
7740+
enhanced-resolve "^5.17.1"
77587741
es-module-lexer "^1.2.1"
77597742
eslint-scope "5.1.1"
77607743
events "^3.2.0"

0 commit comments

Comments
 (0)