Make WordPress Core

Opened 8 years ago

Closed 5 years ago

#36445 closed defect (bug) (duplicate)

force_balance_tags not properly balancing custom HTML tags with dashes in them

Reported by: toddhuish's profile toddhuish Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description

Given the following HTML and having "settings...writing..WordPress should correct invalidly nested XHTML automatically" checked, upon save
This

<amp-ad>
      type="fmpub"
</amp-ad>

results in

<amp -ad>
      type="fmpub"
</amp>

I found this problem while customizing an AMP enabled installation. AMP ads use amp-ad or amp-embed tags, both of which get munged by balance tags. I have attached a proposed fix for this problem but I am not sure what the overall implications are of this change.

--- formatting.php	2016-04-07 15:29:18.000000000 -0700
+++ formatting-fixed.php	2016-04-07 15:29:52.000000000 -0700
@@ -1800,7 +1800,7 @@
 	// WP bug fix for LOVE <3 (and other situations with '<' before a number)
 	$text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);

-	while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
+	while ( preg_match("/<(\/?[\w:-]*)\s*([^>]*)>/", $text, $regex) ) {
 		$newtext .= $tagqueue;

 		$i = strpos($text, $regex[0]);

Attachments (1)

formatting.patch (475 bytes) - added by toddhuish 8 years ago.
Proposed patch with preg_match change

Download all attachments as: .zip

Change History (4)

@toddhuish
8 years ago

Proposed patch with preg_match change

#1 @toddhuish
8 years ago

  • Summary changed from force_balance_tags nor properly balancing custom HTML tags with dashes in them to force_balance_tags not properly balancing custom HTML tags with dashes in them

#2 @swissspidy
8 years ago

  • Keywords has-patch added

#3 @pento
5 years ago

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

Marking this as a duplicate of #47014, which as a more discussion on it.

Note: See TracTickets for help on using tickets.