Coder Social home page Coder Social logo

Comments (7)

davisagli avatar davisagli commented on May 30, 2024

However, how do you represent a special marker that renders to an empty string?

With the appropriate character escape; '\xad' in this case.

from zope.testbrowser.

florianpilz avatar florianpilz commented on May 30, 2024

That does not seem to help. To be concise, I have a linked article named Yet another test article. So in my browser.contents is something like

<a href="http://localhost/portal/++co++3e6e4494-5e6b-11e4-9a68-b8e85636a62a"
   title="go to page 'Yet another test article'">
    Yet ano&shy;ther test ar&shy;tic&shy;le
</a>

All of the following examples throw a LinkNotFoundError (tried it with and without unicode strings):

  • browser.getLink(u'Yet another test article')
  • browser.getLink(u'Yet ano&shy;ther test ar&shy;tic&shy;le')
  • browser.getLink(u'Yet ano\xadther test ar\xadtic\xadle')

from zope.testbrowser.

mgedmin avatar mgedmin commented on May 30, 2024

@florianpilz can you reduce your problem to a testcase? Because the following passes for me, when applied to master:

diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index f9b8550..ec14cbb 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -489,6 +489,28 @@ def test_strip_linebreaks_from_textarea(self):
     """


+def test_soft_hyphens():
+    r"""
+
+    >>> app = TestApp()
+    >>> browser = Browser(wsgi_app=app)
+
+    >>> app.set_next_response(b'''\
+    ... <html><body>
+    ...     <a href="foo">hy&shy;phen&shy;ation</a>
+    ... </body></html>
+    ... ''')
+    >>> browser.open('http://localhost/bar') # doctest: +ELLIPSIS
+    GET /bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink(u'hy\xadphen\xadation')
+    >>> link.url
+    'http://localhost/foo'
+
+    """
+
+
 def test_relative_link():
     """
     RFC 1808 specifies how relative URLs should be resolved, let's see

from zope.testbrowser.

mgedmin avatar mgedmin commented on May 30, 2024

Okay, I can reproduce this in the 4.0 branch:

diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index 915ce48..45f4fad 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -379,6 +379,25 @@ def test_strip_linebreaks_from_textarea(self):
     """


+def test_soft_hyphens():
+    r"""
+
+    >>> browser = Browser()
+    >>> browser.open('''\
+    ... <html><body>
+    ...     <a href="foo">link</a>
+    ... </body></html>
+    ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+    GET /bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink(u'hy\xadphen\xadation')
+    >>> link.url
+    'http://localhost/foo'
+
+    """
+
+
 def test_relative_link():
     """
     RFC 1808 specifies how relative URLs should be resolved, let's see

Fails with LinkNotFoundError.

from zope.testbrowser.

mgedmin avatar mgedmin commented on May 30, 2024

Never mind, I messed up the test case. This passes on the 4.0 branch:

diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index 915ce48..78a9161 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -379,6 +379,25 @@ def test_strip_linebreaks_from_textarea(self):
     """


+def test_soft_hyphens():
+    r"""
+
+    >>> browser = Browser()
+    >>> browser.open('''\
+    ... <html><body>
+    ...     <a href="foo">hy&shy;phen&shy;ation</a>
+    ... </body></html>
+    ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+    GET /bar HTTP/1.1
+    ...
+
+    >>> link = browser.getLink(u'hy\xadphen\xadation')
+    >>> link.url
+    'http://localhost/foo'
+
+    """
+
+
 def test_relative_link():
     """
     RFC 1808 specifies how relative URLs should be resolved, let's see

from zope.testbrowser.

florianpilz avatar florianpilz commented on May 30, 2024

Hm, seems like you are right.

I found out that the UTF-8 representation of shy-Markers works, i.e. using '\xc2\xad' or '\xad'.encode('utf-8'). Therefore it seems to be an encoding issue somewhere else.

Maybe the mechanize Browser is the issue, I cannot tell for certain since you mock some parts out when testing zope.testbrowser.

Anyway, the problem lies definitely in another package. Thanks for helping!

from zope.testbrowser.

florianpilz avatar florianpilz commented on May 30, 2024

Ok nailed it down: We are using Zope2 as the test app, which sets UTF-8 encoding in the header. Mechanize just looks into the header to determine the encoding. Thus it's not an error after all, just cumbersome.

But be aware that using browser.getLink(u'hy\xadphen\xadation') only works in your test setup. Mechanize always uses an encoding, which defaults to latin1. In your tests you obviously mocked that part, since you define the exact response given.

So using the Unicode-representation will not work using a real Mechanize Browser. Instead you have to use the representation of your encoding or encode the text string, e.g. browser.getLink(u'hy\xadphen\xadation'.encode('latin1'))

from zope.testbrowser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.