Opened 10 years ago
Last modified 6 weeks ago
#39472 new defect (bug)
Code tag still parses embeds
| Reported by: | rmens | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Embeds | Version: | 4.7 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
WordPress 4.7.
The 'code' block in the WordPress editor behaves incorrectly.
For example:
<code>Test Test Another www.google.com http://www.google.com https://www.youtube.com/watch?v=JHw6LTuMkNQ Foxtrot Uniform Charlie Kilo </code>
Displays as normal code in the wp-admin, but once published it creates an embed on the page. This should not happen and the contents of the code block should be displayed without embeds.
Attachments (3)
Change History (9)
#1
follow-up:
↓ 2
@
10 years ago
@rmens
The YouTube link would be converted with an embed by WP automatically.
https://codex.wordpress.org/Embeds
WordPress will automatically turn the URL into a YouTube embed and provide a live preview in the visual editor.
If you used say
<code>Test Test
Another
<a href="www.google.com">www.google.com</a>
<a href="http://www.google.com">http://www.google.com</a>
<a href="https://www.youtube.com/watch?v=JHw6LTuMkNQ">https://www.youtube.com/watch?v=JHw6LTuMkNQ</a>
Foxtrot Uniform Charlie Kilo
</code>
#2
in reply to: ↑ 1
@
10 years ago
Replying to lukecavanagh:
@rmens
The YouTube link would be converted with an embed by WP automatically.
I'm aware of this, but should that really happen inside code blocks?
#3
@
10 years ago
@rmens
Not sure if having code blocks around a YouTube link would make any difference currently with the emded.
#4
@
10 years ago
- Component Formatting → Embeds
- Keywords needs-patch added
Agreed that this is bug-worthy, embeds should not be processed within <code> or <pre> tags if at all possible.
#5
@
10 years ago
Also reported as a support forums issue after the upgrade to bbPress 2.x: #meta2469.
This ticket was mentioned in PR #12646 on WordPress/wordpress-develop by @hasnainashfaq.
6 weeks ago
#6
- Keywords has-patch has-unit-tests added; needs-patch removed
## Summary
Fixes #39472. URLs inside <pre> and <code> blocks are meant to be displayed as literal text, but WordPress was converting them to embeds.
This fix protects <pre> and <code> block content with placeholders before URL detection runs, then restores the original content afterward — the same placeholder approach used by wpautop() for <pre> tags.
## Changes
src/wp-includes/class-wp-embed.php: InWP_Embed::autoembed(), extract<pre>and<code>blocks into placeholders before URL scanning, restore them after.tests/phpunit/tests/oembed/WpEmbed.php: Three new tests covering: URL in<pre>not embedded, URL in<code>not embedded, URL outside protected tags is still embedded.
## Test plan
- [x] Run
npm run test:php -- --filter test_autoembed— all 14 tests pass - [ ] Manually create a post with a YouTube URL inside a
<code>block — confirm it renders as literal text, not an embed - [ ] Verify a YouTube URL outside
<code>/<pre>still embeds normally
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Expected output