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

@@ -243,13 +243,16 @@ class TestDataTypes(BaseTest):
l0 = create('file:///etc/test')
self.ae(l0.url_start_at(0), 0)
for trail in '.,]>)\\':
for trail in '.,\\':
lx = create("http://xyz.com" + trail)
self.ae(lx.url_end_at(0), len(lx) - 2)
for trail in ')}]>':
lx = create("http://xyz.com" + trail)
self.ae(lx.url_end_at(0), len(lx) - 1)
l0 = create("ftp://abc/")
self.ae(l0.url_end_at(0), len(l0) - 1)
l2 = create("http://-abcd] ")
self.ae(l2.url_end_at(0), len(l2) - 3)
self.ae(l2.url_end_at(0), len(l2) - 2)
l3 = create("http://ab.de ")
self.ae(l3.url_start_at(4), 0)
self.ae(l3.url_start_at(5), 0)

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)