terrylinooo / githuber-md

Markdown editor plugin for WordPress.
GNU General Public License v3.0
610 stars 89 forks source link

Special symbols in code block is converted #374

Open jencijanos opened 1 month ago

jencijanos commented 1 month ago

Describe the bug

Symbols such as >, <, and " are converted to their ampersand variants when used inside a code block, but they remain unchanged when outside a code block

To reproduce

I create a post and publish it. After I press publish &gt; and &lt; get’s immediately converted to > and < in the original markdown text. The markdown text was not saved correctly to the database. See "Additional context"

Expected behavior

I expect keep original text inside code blocks.

Screenshots

Visual changes after publish

before publish after post is published

Data stored in DB

markdown text in database

Server environment

Clean install, no other plugins or special settings applied.

User environment

Additional context

Data from DB post_content_filtered

i want to keep what i write

one symbol > or "amp" representation &gt;

one symbol < or "amp" representation &lt;

```
one symbol &gt; or &quot;amp&quot; representation &gt;
&lt;title&gt;
```

Expected markdown text

i want to keep what i write

one symbol > or "amp" representation &gt;

one symbol < or "amp" representation &lt;

```
one symbol > or "amp" representation &gt;
<title>
```
jencijanos commented 1 month ago

Example:

Input markdown text:

~~~
({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&apos;'
}
[tag])
~~~

After Publis post in /wp-admin/post.php $_REQUEST['content'] i see:

~~~\r\n({\r\n\\'&\\': \\'&amp;\\',\r\n\\'<\\': \\'&lt;\\',\r\n\\'>\\': \\'&gt;\\',\r\n\\'\\"\\': \\'&quot;\\',\r\n\\"\\'\\": \\'&apos;\\'\r\n}\r\n[tag])\r\n~~~\r\n

And in wp-githuber-md/src/Controllers/Markdown.php function wp_insert_post_data the $post_data['post_content'] contain:

~~~\r\n({\r\n&#039;&amp;&#039;: &#039;&amp;&#039;,\r\n&#039;&lt;&#039;: &#039;&lt;&#039;,\r\n&#039;&gt;&#039;: &#039;&gt;&#039;,\r\n&#039;&quot;&#039;: &#039;&quot;&#039;,\r\n&quot;&#039;&quot;: &#039;&amp;apos;&#039;\r\n}\r\n[tag])\r\n~~~\r\n

The > symbol converted to &gt; but "&gt;" entity isn't changed, not converted to &amp;gt;. Same situation with other symbols

I don't know where these changes happen, but maybe outside the plugin