[#5314] ticket:219 check red links
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 6ef4b68..b34aa6a 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -104,9 +104,18 @@
if shortlink:
href = shortlink.url
self.ext.forge_link_tree_processor.alinks.append(shortlink)
- elif self.ext._use_wiki and ':' not in link:
+ elif self.ext._use_wiki and is_link_with_brackets:
href = h.urlquote(link)
classes += ' notfound'
+ attach_link = link.split('/attachment/')
+ if len(attach_link) == 2 and self.ext._use_wiki:
+ shortlink = M.Shortlink.lookup(attach_link[0])
+ if shortlink:
+ attach_status = ' notfound'
+ for attach in shortlink.ref.artifact.attachments:
+ if attach.filename == attach_link[1]:
+ attach_status = ''
+ classes += attach_status
return href, classes
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 3375b6d..cb48574 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -467,11 +467,15 @@
* Here is a link to [Some page which does not exist]
* Here is a link to [space page]
* Here is a link to [space%20page]
+* Here is a link to [another attach](TEST/attachment/attach.txt)
+* Here is a link to [attach](TEST/attachment/test_root.py)
''',
'labels':'',
'labels_old':'',
'viewable_by-0.id':'all'}
self.app.post('/wiki/TEST/update', params=params)
+ content = file(__file__).read()
+ self.app.post('/wiki/TEST/attach', upload_files=[('file_info', 'test_root.py', content)])
r = self.app.get('/wiki/TEST/')
found_links = 0
for link in r.html.findAll('a'):
@@ -479,7 +483,7 @@
assert 'notfound' not in link.get('class', '')
found_links +=1
if link.contents == ['another page']:
- assert 'notfound' in link.get('class', '')
+ assert 'notfound' not in link.get('class', '')
found_links +=1
if link.contents == ['space page space']:
assert 'notfound' not in link.get('class', '')
@@ -499,7 +503,13 @@
if link.contents == ['[space%20page]']:
assert 'notfound' not in link.get('class', '')
found_links +=1
- assert found_links == 8, 'Wrong number of links found'
+ if link.contents == ['another attach']:
+ assert 'notfound' in link.get('class', '')
+ found_links +=1
+ if link.contents == ['attach']:
+ assert 'notfound' not in link.get('class', '')
+ found_links +=1
+ assert found_links == 10, 'Wrong number of links found'
def test_home_rename(self):
assert 'The resource was found at http://localhost/p/test/wiki/Home/;' in self.app.get('/p/test/wiki/')