WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#7056 closed defect (bug) (fixed)

wptexturize should leave contents of pre tags verbatim

Reported by: nbachiyski Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Formatting Keywords: has-patch wptexturize tested
Focuses: Cc:

Description

Current behaviour:

  • wptexturize('<pre><code></code>--</pre>') gives <pre><code></code>&#8211;</pre>

Expected behavious:

  • wptexturize shouldn't convert the two hyphens to a m-dash and should return <pre><code></code>--</pre>

The problem is that wptexturize doesn't keep it's state if tags are nested.

Also, a test was added. The patched version passes it.

Attachments (3)

texturize-deep-pre.diff (1.4 KB) - added by nbachiyski 6 years ago.
texturize-deep-code.diff (1.6 KB) - added by nbachiyski 5 years ago.
texturize-stack.diff (2.8 KB) - added by nbachiyski 5 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Viper007Bond6 years ago

  • Version set to 2.6

Oh thank you thank you thank you. This'll be a huge help for my code posting plugins.

comment:2 ryan6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [8298]) Hands off pre tags. Props nbachiyski. fixes #7056

comment:3 nbachiyski5 years ago

  • Milestone changed from 2.6 to 2.8
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 2.6 to 2.8

We should do the same with code tags, too. They often contain other tags, as links and in that case wptexturize() breaks the quotes and dashes.

The test from the ticket description was updated to reflect the changes. The patch passes the tests.

comment:4 DD325 years ago

See also: #6969 (<code>/shortcodes)

comment:5 nbachiyski5 years ago

Regex parsing of tags sucks. Setting $next to false doesn't work if you have any tags inside a pre/code/whatever. The current patch doesn't work with two nested pres. So, here are the stacks.

The stacks approach works for any number/kind of nested elements. It also keeps a dynamic list of the not texturizable tags and shortcodes, so that a plugin can modify them. This way you can opt-out your shortcode from wptexturize() (this fixes #6969).

Please, have a look at the unit tests, I would be happy if anybody adds more. They are really useful in this case.

nbachiyski5 years ago

comment:6 Denis-de-Bernardy5 years ago

  • Component changed from General to Formatting

comment:7 nbachiyski5 years ago

  • Keywords tested added

comment:8 ryan5 years ago

See #8321. tt support would need to be merged into this if we go with it.

BTW, this has been running on wp.com for the past 3 weeks.

comment:9 ryan5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [11345]) Handle nested tag in wptexturize(). Props nbachiyski. fixes #7056 see #6969

comment:10 miken325 years ago

Definitely looking forward to this one, it will be in 2.9 I assume?

I wanted to add that <samp> should be added to the list of HTML elements to leave alone. This element "represents (sample) output from a program or computing system."

comment:11 miken325 years ago

  • Cc miken32 added
Note: See TracTickets for help on using tickets.