Commits

Jun Omae committed b79a847

1.1.2dev: merge [12092] from 1.0-stable (fix for #11308)

Comments (0)

Files changed (2)

trac/versioncontrol/web_ui/log.py

 
             if repos:
                 revranges = None
-                if any(c for c in ':-,' if c in revs):
+                if any(c in revs for c in ':-,'):
                     revranges = self._normalize_ranges(repos, path, revs)
-                    revs = None
+                    if revranges:
+                        revs = None
                 if 'LOG_VIEW' in formatter.perm:
                     if revranges:
                         href = formatter.href.log(repos.reponame or None,
                             rev = None
                         href = formatter.href.log(repos.reponame or None,
                                                   path or '/', rev=rev)
-                    if query and (revranges or revs):
+                    if query and '?' in href:
                         query = '&' + query[1:]
                     return tag.a(label, class_='source',
                                  href=href + query + fragment)
                 return None
             seps = splitted_ranges[1::2] + ['']
             ranges = ''.join([str(rev)+sep for rev, sep in zip(revs, seps)])
-            return Ranges(ranges)
+            try:
+                return Ranges(ranges)
+            except ValueError:
+                return None

trac/versioncontrol/web_ui/tests/wikisyntax.py

 from trac.wiki.tests import formatter
 
 
+YOUNGEST_REV = 200
+
+
 def _get_changeset(rev):
     if rev == '1':
         return Mock(message="start", is_viewable=lambda perm: True)
     else:
         raise NoSuchChangeset(rev)
 
+
 def _normalize_rev(rev):
+    if rev is None or rev in ('', 'head'):
+        return YOUNGEST_REV
     try:
-        return int(rev)
+        nrev = int(rev)
+        if nrev <= YOUNGEST_REV:
+            return nrev
     except ValueError:
-        if rev == 'head':
-            return '200'
-        else:
-            raise NoSuchChangeset(rev)
+        pass
+    raise NoSuchChangeset(rev)
+
 
 def _get_node(path, rev=None):
     if path == 'foo':
         return Mock(path=path, rev=rev, isfile=True,
                     is_viewable=lambda resource: True)
 
+
 def _get_repository(reponame):
-    return Mock(reponame=reponame, youngest_rev='200',
+    return Mock(reponame=reponame, youngest_rev=YOUNGEST_REV,
                 get_changeset=_get_changeset,
                 normalize_rev=_normalize_rev,
                 get_node=_get_node)
 
+
 def repository_setup(tc):
     setattr(tc.env, 'get_repository', _get_repository)
     setattr(RepositoryManager(tc.env), 'get_repository', _get_repository)
 ------------------------------
 <p>
 <a class="source" href="/log/?rev=12">log:@12</a>
-<a class="source" href="/log/trunk">log:trunk</a>
+<a class="source" href="/log/trunk?rev=200">log:trunk</a>
 <a class="source" href="/log/trunk?rev=12">log:trunk@12</a>
 <a class="source" href="/log/trunk?revs=12-23">log:trunk@12:23</a>
 <a class="source" href="/log/trunk?revs=12-23">log:trunk@12-23</a>
 [10:20/trunk?verbose=yes&format=changelog]
 ------------------------------
 <p>
-<a class="source" href="/log/?limit=10">log:?limit=10</a>
+<a class="source" href="/log/?rev=200&amp;limit=10">log:?limit=10</a>
 <a class="source" href="/log/?rev=12&amp;limit=10">log:@12?limit=10</a>
-<a class="source" href="/log/trunk?limit=10">log:trunk?limit=10</a>
+<a class="source" href="/log/trunk?rev=200&amp;limit=10">log:trunk?limit=10</a>
 <a class="source" href="/log/trunk?rev=12&amp;limit=10">log:trunk@12?limit=10</a>
 <a class="source" href="/log/?revs=10-20&amp;verbose=yes&amp;format=changelog">[10:20?verbose=yes&amp;format=changelog]</a>
 <a class="source" href="/log/trunk?revs=10-20&amp;verbose=yes&amp;format=changelog">[10:20/trunk?verbose=yes&amp;format=changelog]</a>
 </p>
 ------------------------------
+============================== log: link resolver + invalid ranges
+log:@10-20-30
+log:@10,20-30,40-50-60
+log:@10:20:30
+[10-20-30]
+[10:20:30]
+------------------------------
+<p>
+<a class="source" href="/log/">log:@10-20-30</a>
+<a class="source" href="/log/">log:@10,20-30,40-50-60</a>
+<a class="source" href="/log/">log:@10:20:30</a>
+[10-20-30]
+[10:20:30]
+</p>
+------------------------------
 ============================== Multiple Log ranges
 r12:20,25,35:56,68,69,100-120
 [12:20,25,35:56,68,69,100-120]