Skip to content

Commit

Permalink
Unwrap other if it is a proxy, so the proxy can compare equal to itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Sep 5, 2018
1 parent 024cb9a commit 4d089ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/zope/security/_proxy.c
Expand Up @@ -361,6 +361,10 @@ proxy_richcompare(SecurityProxy* self, PyObject* other, int op)
{
PyObject *result = NULL;

if (Proxy_Check(other)) {
other = ((SecurityProxy*)(other))->proxy.proxy_object;
}

result = PyObject_RichCompare(self->proxy.proxy_object, other, op);
if (result == Py_True || result == Py_False)
return result;
Expand Down
3 changes: 2 additions & 1 deletion src/zope/security/tests/test_proxy.py
Expand Up @@ -1864,7 +1864,8 @@ def testRichCompareProxyWithObjectOK(self):
self.assertTrue(self.p == self.x)

def testRichCompareObjectWithProxyOK(self):
self.assertTrue(self.x == self.p)
# Proxy does not get unwrapped as `Something` class defines `__eq__`.
self.assertFalse(self.x == self.p)

def testRichCompareWithProxyWithProxyOK(self):
self.assertTrue(self.p == self.p)
Expand Down

0 comments on commit 4d089ff

Please sign in to comment.