From dbfb3e2c7eaa4ca8eb69d55c91b67014b4e4a725 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 22 Jun 2017 11:29:35 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#285 --- wire/core/WireMarkupRegions.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/wire/core/WireMarkupRegions.php b/wire/core/WireMarkupRegions.php index 12b693e7..4ec5a7e2 100644 --- a/wire/core/WireMarkupRegions.php +++ b/wire/core/WireMarkupRegions.php @@ -1275,6 +1275,7 @@ class WireMarkupRegions extends Wire { if(!count($regions)) { if($debug) $htmlDocument = str_replace($debugLandmark, "
No regions
$debugLandmark", $htmlDocument); + $recursionLevel--; return 0; } @@ -1393,16 +1394,19 @@ class WireMarkupRegions extends Wire { if(count($xregions) && $recursionLevel < 3) { // see if they can be populated now - $numUpdates += $this->populate($htmlDocument, $xregions); + $numUpdates += $this->populate($htmlDocument, $xregions, $options); } - - if($this->removeRegionTags($htmlDocument)) $numUpdates++; + + // remove region tags and pw-id attributes + if($recursionLevel === 1 && $this->removeRegionTags($htmlDocument)) $numUpdates++; // if there is any leftover markup, place it above the HTML where it would usually go if(strlen($leftoverMarkup)) { $htmlDocument = $leftoverMarkup . $htmlDocument; $numUpdates++; } + + $recursionLevel--; return $numUpdates; } @@ -1410,15 +1414,27 @@ class WireMarkupRegions extends Wire { /** * Remove any or tags present in the markup, leaving their innerHTML contents * + * Also removes data-pw-id and pw-id attributes + * * @param string $html - * @return bool True if tags were removed, false if not + * @return bool True if tags or attributes were removed, false if not * */ protected function removeRegionTags(&$html) { - if(stripos($html, '') === false && strpos($html, '') === false) return false; - $html = preg_replace('!]*>|>)!i', '', $html); - //$html = str_ireplace(array('', ''), '', $html); - return true; + + $updated = false; + + if(stripos($html, '') !== false || strpos($html, '') !== false) { + $html = preg_replace('!]*>|>)!i', '', $html); + $updated = true; + } + + if(stripos($html, ' data-pw-id=') || stripos($html, ' pw-id=')) { + $html = preg_replace('/(<[^>]+)(?: data-pw-id| pw-id)=["\']?[^>\s"\']+["\']?/i', '$1', $html); + $updated = true; + } + + return $updated; } /**