Changeset - 4e2e6371f79a
[Not reviewed]
default
0 4 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
helpers: in urlify_text, use <br> for newlines in pre-formatted text so it can be cut'n'pasted correctly

Before, when copying the preformatted nice looking ASCII-artsy text in a PR or
changeset description from a browser to a text editor, it would be pasted as
text without newline. Simply put, copy/paste ignores that it is inside a <pre>
/ white-space:pre-wrap section.

Instead, translate newlines to <br> which always translates to a newline when
pasted.
4 files changed with 26 insertions and 52 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -1293,24 +1293,25 @@ def urlify_text(s, repo_name=None, link_
 
        s = s.rstrip()
 
    else:
 
        s = truncatef(s, truncate, whole_word=True)
 
    s = html_escape(s)
 
    if repo_name is not None:
 
        s = urlify_changesets(s, repo_name)
 
    if stylize:
 
        s = desc_stylize(s)
 
    s = _urlify_text(s)
 
    if repo_name is not None:
 
        s = urlify_issues(s, repo_name, link_)
 
    s = MENTIONS_REGEX.sub(_mentions_replace, s)
 
    s = s.replace('\r\n', '<br/>').replace('\n', '<br/>')
 
    return literal(s)
 

	
 

	
 
def _urlify_changeset_replace_f(repo_name):
 
    from pylons import url  # doh, we need to re-import url to mock it later
 
    def urlify_changeset_replace(match_obj):
 
        rev = match_obj.group(0)
 
        return '<a class="revision-link" href="%(url)s">%(rev)s</a>' % {
 
         'url': url('changeset_home', repo_name=repo_name, revision=rev),
 
         'rev': rev,
 
        }
 
    return urlify_changeset_replace
kallithea/tests/functional/test_files.py
Show inline comments
 
@@ -90,29 +90,29 @@ class TestFilesController(TestController
 
                                    revision=r[1],
 
                                    f_path='/'))
 

	
 
            response.mustcontain("""@ r%s:%s""" % (r[0], r[1][:12]))
 

	
 
    def test_file_source(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='index',
 
                                    repo_name=HG_REPO,
 
                                    revision='8911406ad776fdd3d0b9932a2e89677e57405a48',
 
                                    f_path='vcs/nodes.py'))
 

	
 
        response.mustcontain("""<div class="commit">Partially implemented <a class="issue-tracker-link" href="https://issues.example.com/vcs_test_hg/issue/16">#16</a>. filecontent/commit message/author/node name are safe_unicode now.
 
In addition some other __str__ are unicode as well
 
Added test for unicode
 
Improved test to clone into uniq repository.
 
removed extra unicode conversion in diff.</div>
 
        response.mustcontain("""<div class="commit">Partially implemented <a class="issue-tracker-link" href="https://issues.example.com/vcs_test_hg/issue/16">#16</a>. filecontent/commit message/author/node name are safe_unicode now.<br/>"""
 
"""In addition some other __str__ are unicode as well<br/>"""
 
"""Added test for unicode<br/>"""
 
"""Improved test to clone into uniq repository.<br/>"""
 
"""removed extra unicode conversion in diff.</div>
 
""")
 

	
 
        response.mustcontain("""<option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">default at 8911406ad776</option>""")
 

	
 
    def test_file_source_history(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='history',
 
                                    repo_name=HG_REPO,
 
                                    revision='tip',
 
                                    f_path='vcs/nodes.py'),
 
                                extra_environ={'HTTP_X_PARTIAL_XHR': '1'},)
 
        assert response.body == HG_NODE_HISTORY
kallithea/tests/models/test_dump_html_mails.ref.html
Show inline comments
 
@@ -85,27 +85,25 @@ View Comment: http://comment.org
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.
 

	
 
 - and here it ends indented.</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -244,27 +242,25 @@ View Comment: http://comment.org
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.
 

	
 
 - and here it ends indented.</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -421,27 +417,25 @@ View Comment: http://comment.org
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.
 

	
 
 - and here it ends indented.</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -598,27 +592,25 @@ View Comment: http://comment.org
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.
 

	
 
 - and here it ends indented.</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the new comment.<br/><br/> - and here it ends indented.</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -719,26 +711,25 @@ Subject: Test Message
 
    </tr>
 
</table>
 
                    </td>
 
                </tr>
 
                <tr>
 
                    <td height="30px" colspan="3"></td>
 
                </tr>
 
                <tr>
 
                    <td></td>
 
                    <td>
 
<table cellpadding="0" cellspacing="0" border="0" width="100%">
 
    <tr>
 
        <td style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the body of the test message
 
 - nothing interesting here except indentation.</div></td>
 
        <td style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">This is the body of the test message<br/> - nothing interesting here except indentation.</div></td>
 
    </tr>
 
</table>
 
                    </td>
 
                    <td></td>
 
                </tr>
 
                <tr>
 
                    <td height="30px" colspan="3"></td>
 
                </tr>
 
            </table>
 
        </td>
 
        <td width="30px"></td>
 
    </tr>
 
@@ -977,26 +968,25 @@ View Pull Request: http://pr.org/7
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 
    <tr>
 
        <td>
 
            <div>
 
                Description:
 
            </div>
 
        </td>
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 
    <tr>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff
 
 - please approve indented!</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff<br/> - please approve indented!</div></div>
 
        </td>
 
    </tr>
 
    <tr><td height="15px"></td></tr>
 
    <tr>
 
        <td>
 
            <div>Changesets:</div>
 
        </td>
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 

	
 
    <tr>
 
        <td style="font-family:Helvetica,Arial,sans-serif">
 
@@ -1151,26 +1141,25 @@ View Pull Request: http://pr.org/7
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 
    <tr>
 
        <td>
 
            <div>
 
                Description:
 
            </div>
 
        </td>
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 
    <tr>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff
 
 - please approve indented!</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap;color:#395fa0"><div class="formatted-fixed">This PR is awesome because it does stuff<br/> - please approve indented!</div></div>
 
        </td>
 
    </tr>
 
    <tr><td height="15px"></td></tr>
 
    <tr>
 
        <td>
 
            <div>Changesets:</div>
 
        </td>
 
    </tr>
 
    <tr><td height="10px"></td></tr>
 

	
 
    <tr>
 
        <td style="font-family:Helvetica,Arial,sans-serif">
 
@@ -1308,27 +1297,25 @@ View Comment: http://pr.org/comment
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -1473,27 +1460,25 @@ View Comment: http://pr.org/comment
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -1656,27 +1641,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -1839,27 +1822,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -2021,27 +2002,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -2203,27 +2182,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -2391,27 +2368,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
 
@@ -2579,27 +2554,25 @@ View Comment: http://pr.org/comment
 
            </td>
 
            <td width="20px"></td>
 
        </tr>
 
        <tr>
 
            <td height="10px" colspan="3" style="border-bottom:1px solid #ddd"></td>
 
        </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
    <tr>
 
        <td width="20px"></td>
 
        <td>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!
 

	
 
 - and indented on second line</div></div>
 
            <div style="font-family:Lucida Console,Consolas,Monaco,Inconsolata,Liberation Mono,monospace;white-space:pre-wrap"><div class="formatted-fixed">Me too!<br/><br/> - and indented on second line</div></div>
 
        </td>
 
        <td width="20px"></td>
 
    </tr>
 
    <tr>
 
        <td height="10px" colspan="3"></td>
 
    </tr>
 
</table>
 
        </td>
 
    </tr>
 
    <tr>
 
        <td height="30px"></td>
 
    </tr>
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -299,27 +299,27 @@ class TestLibs(TestController):
 
       """this should-000 00"""),
 
      ("longtextffffffffff rev 123123123123",
 
       """longtextffffffffff rev url[123123123123]"""),
 
      ("rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
 
       """rev ffffffffffffffffffffffffffffffffffffffffffffffffff"""),
 
      ("ffffffffffff some text traalaa",
 
       """url[ffffffffffff] some text traalaa"""),
 
       ("""Multi line
 
       123123123123
 
       some text 123123123123
 
       sometimes !
 
       """,
 
       """Multi line\n"""
 
       """       url[123123123123]\n"""
 
       """       some text url[123123123123]\n"""
 
       """Multi line<br/>"""
 
       """       url[123123123123]<br/>"""
 
       """       some text url[123123123123]<br/>"""
 
       """       sometimes !"""),
 
    ])
 
    def test_urlify_changesets(self, sample, expected):
 
        def fake_url(self, *args, **kwargs):
 
            return '/some-url'
 

	
 
        expected = self._quick_url(expected)
 

	
 
        with mock.patch('pylons.url', fake_url):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name') == expected
 

	
 
@@ -333,26 +333,26 @@ class TestLibs(TestController):
 
      ("http://svn.apache.org/repos",
 
       """url[http://svn.apache.org/repos]""",
 
       "http://svn.apache.org/repos"),
 
      ("from rev a also rev http://google.com",
 
       """from rev a also rev url[http://google.com]""",
 
       "http://google.com"),
 
      ("http://imgur.com/foo.gif inline http://imgur.com/foo.gif ending http://imgur.com/foo.gif",
 
       """url[http://imgur.com/foo.gif] inline url[http://imgur.com/foo.gif] ending url[http://imgur.com/foo.gif]""",
 
       "http://imgur.com/foo.gif"),
 
      ("""Multi line
 
       https://foo.bar.example.com
 
       some text lalala""",
 
       """Multi line\n"""
 
       """       url[https://foo.bar.example.com]\n"""
 
       """Multi line<br/>"""
 
       """       url[https://foo.bar.example.com]<br/>"""
 
       """       some text lalala""",
 
       "https://foo.bar.example.com"),
 
      ("@mention @someone",
 
       """<b>@mention</b> <b>@someone</b>""",
 
       ""),
 
      ("deadbeefcafe 123412341234",
 
       """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a> <a class="revision-link" href="/repo_name/changeset/123412341234">123412341234</a>""",
 
       ""),
 
      # tags are covered by test_tag_extractor
 
    ])
 
    def test_urlify_test(self, sample, expected, url_):
 
        from kallithea.lib.helpers import urlify_text
0 comments (0 inline, 0 general)