Skip to content

Commit c899a4b

Browse files
author
Richard Jones
committed
add tests for and fix alex's examples
1 parent 4601b7c commit c899a4b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

roundup/cgi/templating.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,11 @@ class StringHTMLProperty(HTMLProperty):
12491249
(?P<url>
12501250
(
12511251
(ht|f)tp(s?):// # protocol
1252-
([\w]+:\w+@)? # username/password
1253-
([\w\-]+\.)+ # hostname
1254-
[\w]{2,5} # TLD
1252+
([\w]+(:\w+)?@)? # username/password
1253+
([\w\-]+) # hostname
1254+
((\.[\w-]+)+)? # .domain.etc
12551255
| # ... or ...
1256+
([\w]+(:\w+)?@)? # username/password
12561257
www\. # "www."
12571258
([\w\-]+\.)+ # hostname
12581259
[\w]{2,5} # TLD

test/test_templating.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def test_url_match(self):
9494
def t(s, nothing=False, **groups):
9595
m = StringHTMLProperty.hyper_re.search(s)
9696
if nothing:
97-
self.assertEquals(m, None, '%r matched'%s)
97+
if m:
98+
self.assertEquals(m, None, '%r matched (%r)'%(s, m.groupdict()))
9899
return
99100
else:
100101
self.assertNotEquals(m, None, '%r did not match'%s)
@@ -104,7 +105,11 @@ def t(s, nothing=False, **groups):
104105
groups[g], s))
105106

106107
#t('123.321.123.321', 'url')
108+
t('http://localhost/', url='http://localhost/')
107109
t('http://roundup.net/', url='http://roundup.net/')
110+
t('http://richard@localhost/', url='http://richard@localhost/')
111+
t('http://richard:sekrit@localhost/',
112+
url='http://richard:sekrit@localhost/')
108113
t('<HTTP://roundup.net/>', url='HTTP://roundup.net/')
109114
t('www.a.ex', url='www.a.ex')
110115
t('foo.a.ex', nothing=True)
@@ -117,6 +122,8 @@ def t(s, nothing=False, **groups):
117122
118123
t('i1', **{'class':'i', 'id':'1'})
119124
t('item123', **{'class':'item', 'id':'123'})
125+
t('www.user:[email protected]', email='[email protected]')
126+
t('user:[email protected]', url='user:[email protected]')
120127

121128
def test_url_replace(self):
122129
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')

0 commit comments

Comments
 (0)