-
Notifications
You must be signed in to change notification settings - Fork 113
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
Compatible with facebook HHVM 3.2 #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ php: | |
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- hhvm-nightly | ||
|
||
notifications: | ||
irc: "irc.freenode.net#masterminds" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,8 @@ class DOMTreeBuilder implements EventHandler | |
*/ | ||
protected $quirks = true; | ||
|
||
protected $errors = array(); | ||
|
||
public function __construct($isFragment = false, array $options = array()) | ||
{ | ||
$this->options = $options; | ||
|
@@ -156,7 +158,7 @@ public function __construct($isFragment = false, array $options = array()) | |
$dt = $impl->createDocumentType('html'); | ||
// $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt); | ||
$this->doc = $impl->createDocument(null, null, $dt); | ||
$this->doc->errors = array(); | ||
$this->errors = array(); | ||
|
||
$this->current = $this->doc; // ->documentElement; | ||
|
||
|
@@ -195,7 +197,6 @@ public function document() | |
*/ | ||
public function fragment() | ||
{ | ||
$this->frag->errors = $this->doc->errors; | ||
return $this->frag; | ||
} | ||
|
||
|
@@ -337,6 +338,9 @@ public function startTag($name, $attributes = array(), $selfClosing = false) | |
// to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes | ||
// see https://bugs.php.net/bug.php?id=67459 | ||
$this->pushes[spl_object_hash($ele)] = array($pushes, $ele); | ||
|
||
// SEE https://github.com/facebook/hhvm/issues/2962 | ||
$ele->setAttribute('html5-php-fake-id-attribute', spl_object_hash($ele)); | ||
} | ||
|
||
foreach ($attributes as $aName => $aVal) { | ||
|
@@ -438,7 +442,13 @@ public function endTag($name) | |
return; | ||
} | ||
|
||
$cid = spl_object_hash($this->current); | ||
// https://github.com/facebook/hhvm/issues/2962 | ||
if ($cid = $this->current->getAttribute('html5-php-fake-id-attribute')) { | ||
$this->current->removeAttribute('html5-php-fake-id-attribute'); | ||
} else { | ||
$cid = spl_object_hash($this->current); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing appears to be off in characters surrounding the if/else. |
||
// remove the namespaced definded by current node | ||
if (isset($this->pushes[$cid])) { | ||
for ($i = 0; $i < $this->pushes[$cid][0]; $i ++) { | ||
|
@@ -501,7 +511,12 @@ public function eof() | |
|
||
public function parseError($msg, $line = 0, $col = 0) | ||
{ | ||
$this->doc->errors[] = sprintf("Line %d, Col %d: %s", $line, $col, $msg); | ||
$this->errors[] = sprintf("Line %d, Col %d: %s", $line, $col, $msg); | ||
} | ||
|
||
public function getErrors() | ||
{ | ||
return $this->errors; | ||
} | ||
|
||
public function cdata($data) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ class OutputRules implements \Masterminds\HTML5\Serializer\RulesInterface | |
|
||
const IM_IN_MATHML = 3; | ||
|
||
private $hasHTML5 = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this meant to be private or should it be protected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is just a little public props = dependency |
||
|
||
protected $traverser; | ||
|
||
protected $encode = false; | ||
|
@@ -40,6 +42,9 @@ public function __construct($output, $options = array()) | |
|
||
$this->outputMode = static::IM_IN_HTML; | ||
$this->out = $output; | ||
|
||
// If HHVM, see https://github.com/facebook/hhvm/issues/2727 | ||
$this->hasHTML5 = defined('ENT_HTML5') && !defined('HHVM_VERSION'); | ||
} | ||
|
||
public function setTraverser(\Masterminds\HTML5\Serializer\Traverser $traverser) | ||
|
@@ -83,15 +88,20 @@ public function element($ele) | |
} | ||
|
||
$this->openTag($ele); | ||
if (Elements::isA($name, Elements::TEXT_RAW)) { | ||
foreach ($ele->childNodes as $child) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't iterating over the child nodes be done by the traverser? Why was it moved into the output rules? I'm also curious what TEXT_RAW is a special case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <script>
//<![CDATA[
alert(1)
//]]>
</script>
// <![CDATA[
alert(1)
//]]> |
||
$this->wr($child->data); | ||
} | ||
} else { | ||
// Handle children. | ||
if ($ele->hasChildNodes()) { | ||
$this->traverser->children($ele->childNodes); | ||
} | ||
|
||
// Handle children. | ||
if ($ele->hasChildNodes()) { | ||
$this->traverser->children($ele->childNodes); | ||
} | ||
|
||
// Close out the SVG or MathML special handling. | ||
if ($name == 'svg' || $name == 'math') { | ||
$this->outputMode = static::IM_IN_HTML; | ||
// Close out the SVG or MathML special handling. | ||
if ($name == 'svg' || $name == 'math') { | ||
$this->outputMode = static::IM_IN_HTML; | ||
} | ||
} | ||
|
||
// If not unary, add a closing tag. | ||
|
@@ -285,7 +295,8 @@ protected function enc($text, $attribute = false) | |
|
||
// If we are in PHP 5.4+ we can use the native html5 entity functionality to | ||
// convert the named character references. | ||
if (defined('ENT_HTML5')) { | ||
|
||
if ($this->hasHTML5) { | ||
return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false); | ||
} // If a version earlier than 5.4 html5 entities are not entirely handled. | ||
// This manually handles them. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not all that familiar with HHVM. What is
systemlib.phpreflection_hni
and why is it blacklisted but not part of the repo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a phpunit/codecoverage limitation
I have commented it here https://github.com/goetas/html5-php/commit/f902b05cc252721e5440f3437d0c5de3e0a8d789#comments
It could blacklisted by default, but it is a @sebastianbergmann issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I could take care of this in PHP_CodeCoverage. But IMHO it should be taken care of in HHVM. HHVM's code coverage API should not expose data for
systemlib*
.@ptarjan @sgolemon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can (and should) fix it. Can you cook up a small example and submit an issue please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebastianbergmann @ptarjan I've opened an issue here: facebook/hhvm#2992