Skip to content

Commit

Permalink
Bug fix. See: #52
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Aug 18, 2015
1 parent 5b69a25 commit c8f6b26
Showing 1 changed file with 52 additions and 32 deletions.
84 changes: 52 additions & 32 deletions src/includes/classes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected function compileCssTagFragsIntoParts(array $css_tag_frags, $for)
}
} elseif ($_css_tag_frag['link_href']) {
if (($_css_tag_frag['link_href'] = $this->resolveRelativeUrl($_css_tag_frag['link_href']))) {
if (($_css_code = $this->remote($_css_tag_frag['link_href']))) {
if (($_css_code = $this->stripUtf8Bom($this->remote($_css_tag_frag['link_href'])))) {
$_css_code = $this->resolveCssRelatives($_css_code, $_css_tag_frag['link_href']);
$_css_code = $this->resolveResolvedCssImports($_css_code, $_css_tag_frag['media']);

Expand All @@ -575,6 +575,7 @@ protected function compileCssTagFragsIntoParts(array $css_tag_frags, $for)
}
} elseif ($_css_tag_frag['style_css']) {
$_css_code = $_css_tag_frag['style_css'];
$_css_code = $this->stripUtf8Bom($_css_code);
$_css_code = $this->resolveCssRelatives($_css_code);
$_css_code = $this->resolveResolvedCssImports($_css_code, $_css_tag_frag['media']);

Expand Down Expand Up @@ -1037,7 +1038,9 @@ protected function resolveResolvedCssImportsCb(array $m)
return $m[0]; // Not possible; different media.
}
if (($css = $this->remote($m['url']))) {
$css = $this->resolveCssRelatives($css, $m['url']);
if (($css = $this->stripUtf8Bom($css))) {
$css = $this->resolveCssRelatives($css, $m['url']);
}
}
return $css;
}
Expand Down Expand Up @@ -1100,24 +1103,24 @@ protected function resolveCssRelativesUrlCb(array $m)
return $m['url_'].$m['open_bracket'].$m['open_encap'].$this->resolveRelativeUrl($m['url'], $this->current_base).$m['close_encap'].$m['close_bracket'];
}

/**
* Force absolute relative paths in CSS.
*
* @since 150511 Improving CSS handling.
*
* @param string $css Raw CSS code.
*
* @return string CSS code (possibly altered here).
*/
protected function forceAbsRelativePathsInCss($css)
{
if (!($css = (string) $css)) {
return $css; // Nothing to do.
}
$regex = '/(?:[a-z0-9]+\:)?\/\/'.preg_quote($this->currentUrlHost(), '/').'\//i';

return preg_replace($regex, '/', $css); // Absolute relative paths.
}
/**
* Force absolute relative paths in CSS.
*
* @since 150511 Improving CSS handling.
*
* @param string $css Raw CSS code.
*
* @return string CSS code (possibly altered here).
*/
protected function forceAbsRelativePathsInCss($css)
{
if (!($css = (string) $css)) {
return $css; // Nothing to do.
}
$regex = '/(?:[a-z0-9]+\:)?\/\/'.preg_quote($this->currentUrlHost(), '/').'\//i';

return preg_replace($regex, '/', $css); // Absolute relative paths.
}

/********************************************************************************************************/

Expand Down Expand Up @@ -2048,14 +2051,14 @@ protected function maybeCompressInlineJsCode($html)

if ($benchmark) {
$this->benchmark->addData(
__FUNCTION__,
compact(
'js_tag_frags',
'js_tag_frags_script_js_parts',
'js_tag_frags_script_js_part_placeholders',
'js_tag_frags_script_js_part_placeholder_key_replacements'
)
);
__FUNCTION__,
compact(
'js_tag_frags',
'js_tag_frags_script_js_parts',
'js_tag_frags_script_js_part_placeholders',
'js_tag_frags_script_js_part_placeholder_key_replacements'
)
);
}
}
}
Expand Down Expand Up @@ -2289,6 +2292,23 @@ protected function removeNumericKeysDeep(array $array, $___recursion = false)
* String Utilities
*/

/**
* Removes UTF-8 BOM (Byte Order Marker).
*
* @since 15xxxx Correcting bug in CSS compilation.
*
* @param string $string Input string to strip.
*
* @return string Stripped string.
*/
protected function stripUtf8Bom($string)
{
if (!($string = (string) $string)) {
return $string;
}
return preg_replace('/^\xEF\xBB\xBF/', '', $string);
}

/**
* Escapes regex special chars deeply (i.e. `preg_quote()` deeply).
*
Expand Down Expand Up @@ -3228,7 +3248,7 @@ protected function parseUrl($url_uri_query_fragment, $component = null, $normali
* @return array|string|int|null {@inheritdoc}
*
* @see parseUrl()
* @inheritdoc parseUrl()
* {@inheritdoc} parseUrl()
*/
protected function mustParseUrl() // Arguments are NOT listed here.
{
Expand Down Expand Up @@ -3320,7 +3340,7 @@ protected function unparseUrl(array $parsed, $normalize = null)
* @return string {@inheritdoc}
*
* @see unparseUrl()
* @inheritdoc unparseUrl()
* {@inheritdoc} unparseUrl()
*/
protected function mustUnparseUrl() // Arguments are NOT listed here.
{
Expand Down Expand Up @@ -3365,7 +3385,7 @@ protected function parseUriParts($url_uri_query_fragment, $normalize = null)
* @return array|null {@inheritdoc}
*
* @see parseUriParts()
* @inheritdoc parseUriParts()
* {@inheritdoc} parseUriParts()
*/
protected function mustParseUriParts() // Arguments are NOT listed here.
{
Expand Down Expand Up @@ -3410,7 +3430,7 @@ protected function parseUri($url_uri_query_fragment, $normalize = null, $include
* @return string|null {@inheritdoc}
*
* @see parseUri()
* @inheritdoc parseUri()
* {@inheritdoc} parseUri()
*/
protected function mustParseUri() // Arguments are NOT listed here.
{
Expand Down

0 comments on commit c8f6b26

Please sign in to comment.