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

Restrict base tag config to processHtml method #2458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,20 @@ private function processHtml()
$acceptedmedia = Stylesheet::$ACCEPTED_GENERIC_MEDIA_TYPES;
$acceptedmedia[] = $this->options->getDefaultMediaType();

$protocol = $this->getProtocol();
$baseHost = $this->getBaseHost();
$basePath = $this->getBasePath();

// <base href="" />
$base_nodes = $this->dom->getElementsByTagName("base");
if ($base_nodes->length && ($href = $base_nodes->item(0)->getAttribute("href"))) {
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($href);
[$protocol, $baseHost, $basePath] = Helpers::explode_url($href);
}

// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
$this->css->set_protocol($protocol);
$this->css->set_host($baseHost);
$this->css->set_base_path($basePath);

// Get all the stylesheets so that they are processed in document order
$xpath = new DOMXPath($this->dom);
Expand Down Expand Up @@ -644,7 +648,7 @@ private function processHtml()
}

$url = $tag->getAttribute("href");
$url = Helpers::build_url($this->protocol, $this->baseHost, $this->basePath, $url);
$url = Helpers::build_url($protocol, $baseHost, $basePath, $url);

$this->css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
}
Expand Down Expand Up @@ -675,18 +679,18 @@ private function processHtml()
}

// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
$this->css->set_protocol($protocol);
$this->css->set_host($baseHost);
$this->css->set_base_path($basePath);

$this->css->load_css($css, Stylesheet::ORIG_AUTHOR);
break;
}

// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
$this->css->set_protocol($protocol);
$this->css->set_host($baseHost);
$this->css->set_base_path($basePath);
}
}

Expand Down