Make WordPress Core

Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#18575 closed defect (bug) (worksforme)

wptexturize modifies code inside tag attributes

Reported by: iamcal's profile iamcal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: Formatting Keywords: has-patch reporter-feedback
Focuses: Cc:

Description

In certain circumstances, wptexturize() will try to smart quote things inside attributes, screwing up the markup. For example:

[hello <a href="foo[bar]('baz')">world</a>

The tokenizer that generates $textarr will split the text like this:

0: [hello <a href="foo[bar]
1:('baz')">world
2:</a>

and so element 1 gets treated like non-tag text even though it's from an attribute. the easy fix is to not allow starting braces inside a brace set:

old:

$textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

new:

$textarr = preg_split('/(<[^<]*>|\[[^\[]*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

this happens on trunk. code is in wp-includes/formatting.php. after the patch, the tokenizer works as intended:

0: [hello
1: <a href="foo[bar]('baz')">
2: world
3: </a>

Attachments (2)

18575.patch (538 bytes) - added by SergeyBiryukov 13 years ago.
18575_test.patch (708 bytes) - added by iamcal 13 years ago.
test case

Download all attachments as: .zip

Change History (8)

#1 @iamcal
13 years ago

  • Summary changed from wptexturize modified code inside tag attributes to wptexturize modifies code inside tag attributes

#2 @SergeyBiryukov
13 years ago

  • Keywords has-patch needs-unit-tests added

Related: #18549

@iamcal
13 years ago

test case

#3 @SergeyBiryukov
13 years ago

  • Keywords needs-unit-tests removed

#4 @nacin
13 years ago

  • Version changed from 3.3 to 3.2

Thanks for the test case. Could we make it be a valid href, or use a different attribute? This seems a bit off.

#5 @nacin
11 years ago

  • Keywords reporter-feedback added
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

As I indicated two years ago, [hello <a href="foo[bar]('baz')">world</a> just isn't a real-world enough test case to understand what is happening here. I'm going to close this for now.

#6 @nacin
11 years ago

This look likes the real-world example: #12690.

Note: See TracTickets for help on using tickets.