Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved hash generation for t:attr attribute (Fixes #23)
In certain edge case we can have spl_object_hash collisions, so lets use also some node data
- Loading branch information
7f34b8a
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.
Collision is still possible, if both nodes have the same syntax. But I guess that in that case collision probably doesn't matter.
7f34b8a
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.
@Soukiii I'm aware of it, but there is a PHP bug regarding the PHP's DOMDocument implementation (see https://bugs.php.net/bug.php?id=67459)
My solution is just a patch. In a ideal solution, since DOM objects are still alive,
spl_object_hash
should be enough.I can not use your solution (
uniq
on similar random generators) because there are many plugins that relies on the non random value returned byAttrAttribute::getVarname
(t:att-append
,t:trans-attr
at least).7f34b8a
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 realize my solution is wrong - it was just quick patch.
But this doesn't work if there is attr and attr-append on one node - they share variable but XML changes during proccesing.
<div t:attr="class='row'" t:attr-append=" class=' even'"></div>
7f34b8a
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.
huh! Good point!
Re-opening the issue #23
7f34b8a
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.
In a previous version of twital i tried to:
t:id
attributet:id
attribute (when available) instead ofmd5($node->ownerDocument->saveXML($node))
t:id
attributes.This solution is more "messy" but has can fix the problem exposed here by you.
What do you think about?
7f34b8a
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.
But it looks like that combination of attr and attr-append didn't work even before that change.
7f34b8a
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.
That is like what I tried to do. I tried to assign unique ID to special attribute but I didn't make it work. But my mistake was that I tried to use existing
__attr__
7f34b8a
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.
Today i will try to create a PR on this way.
7f34b8a
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.
See #24