Fix trailing parentheses in URLs not being detected

Also fix URLs starting near the end of the line not being detected.

Fixes #3688
This commit is contained in:
Kovid Goyal
2021-06-04 18:13:36 +05:30
parent a8d1c73fec
commit 81411e6b54
8 changed files with 124 additions and 86 deletions

View File

@@ -864,3 +864,28 @@ class TestScreen(BaseTest):
w('#P')
w('#R')
ac(9, 10)
def test_detect_url(self):
s = self.create_screen(cols=30)
def ae(expected, x=3, y=0):
s.detect_url(x, y)
url = ''.join(s.text_for_marked_url())
self.assertEqual(expected, url)
def t(url, x=0, y=0, before='', after=''):
s.reset()
s.cursor.x = x
s.cursor.y = y
s.draw(before + url + after)
ae(url, x=x + 1 + len(before), y=y)
t('http://moo.com')
t('http://moo.com/something?else=+&what-')
for (st, e) in '() {} [] <>'.split():
t('http://moo.com', before=st, after=e)
for trailer in ')-=]}':
t('http://moo.com' + trailer)
for trailer in '{([':
t('http://moo.com', after=trailer)
t('http://moo.com', x=s.columns - 9)