Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix properties split on base64 encoded url content #79

Merged
merged 1 commit into from
Apr 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/CssToInlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ public function convert($outputXHTML = false)
$definedStyles = (string) $stylesAttribute->value;

// split into properties
$definedProperties = (array) explode(';', $definedStyles);

$definedProperties = $this->splitIntoProperties($definedStyles);
// loop properties
foreach ($definedProperties as $property) {
// validate property
Expand Down Expand Up @@ -275,7 +274,7 @@ public function convert($outputXHTML = false)

if ($originalStyle != '') {
$originalProperties = array();
$originalStyles = (array) explode(';', $originalStyle);
$originalStyles = $this->splitIntoProperties($originalStyle);

foreach ($originalStyles as $property) {
// validate property
Expand Down Expand Up @@ -305,7 +304,7 @@ public function convert($outputXHTML = false)
$definedStyles = (string) $stylesAttribute->value;

// split into properties
$definedProperties = (array) explode(';', $definedStyles);
$definedProperties = $this->splitIntoProperties($definedStyles);

// loop properties
foreach ($definedProperties as $property) {
Expand Down Expand Up @@ -365,7 +364,7 @@ public function convert($outputXHTML = false)
if ($this->stripOriginalStyleTags) {
$this->stripOriginalStyleTags($xPath);
}

// should we output XHTML?
if ($outputXHTML) {
// set formating
Expand Down Expand Up @@ -400,6 +399,28 @@ public function convert($outputXHTML = false)
return $html;
}

/**
* Split a style string into an array of properties.
* The returned array can contain empty strings.
*
* @param string $styles ex: 'color:blue;font-size:12px;'
* @return array an array of strings containing css property ex: array('color:blue','font-size:12px')
*/
private function splitIntoProperties($styles) {
$properties = (array) explode(';', $styles);

for ($i = 0; $i < count($properties); $i++) {
// If next property begins with base64,
// Then the ';' was part of this property (and we should not have split on it).
if (isset($properties[$i + 1]) && strpos($properties[$i + 1], 'base64,') === 0) {
$properties[$i] .= ';' . $properties[$i + 1];
$properties[$i + 1] = '';
$i += 1;
}
}
return $properties;
}

/**
* Get the encoding to use
*
Expand Down Expand Up @@ -506,7 +527,7 @@ private function processCSS()
private function processCSSProperties($propertyString)
{
// split into chunks
$properties = (array) explode(';', $propertyString);
$properties = $this->splitIntoProperties($propertyString);

// init var
$pairs = array();
Expand Down Expand Up @@ -567,7 +588,7 @@ public function setCSS($css)
*
* @return void
* @param string $encoding The encoding to use.
*
*
* @deprecated Doesn't have any effect
*/
public function setEncoding($encoding)
Expand Down