Anonymous avatar Anonymous committed 37fd9fa

Explicitely specify the allowed characters that can start and end TracLinks (`shref` form). Should fix #2240 and probably also #1153.

Comments (0)

Files changed (3)

trac/wiki/formatter.py

 
     QUOTED_STRING = r"'[^']+'|\"[^\"]+\""
 
-    SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])|&(?!lt;)|[^|&\s])"
-    SHREF_TARGET_LAST_CHAR = r"[^|'~_\.,&\s\)\]:?!]"
+    SHREF_TARGET_FIRST = r"[\w/?!#@]"
+    SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])|&(?!lt;|gt;)|[^|&\s])"
+    SHREF_TARGET_LAST = r"[a-zA-Z0-9/=]" # we don't want "_"
 
     LHREF_RELATIVE_TARGET = r"[/.][^\s[\]]*"
 
 
     _post_rules = [
         # shref corresponds to short TracLinks, i.e. sns:stgt
-        r"(?P<shref>((?P<sns>%s):(?P<stgt>%s|%s*%s)))" \
+        r"(?P<shref>((?P<sns>%s):(?P<stgt>%s|%s(?:%s*%s)?)))" \
         % (LINK_SCHEME, QUOTED_STRING,
-           SHREF_TARGET_MIDDLE, SHREF_TARGET_LAST_CHAR),
+           SHREF_TARGET_FIRST, SHREF_TARGET_MIDDLE, SHREF_TARGET_LAST),
         # lhref corresponds to long TracLinks, i.e. [lns:ltgt label?]
         r"(?P<lhref>\[(?:(?P<lns>%s):(?P<ltgt>%s|[^\]\s]*)|(?P<rel>%s))"
         r"(?:\s+(?P<label>%s|[^\]]+))?\])" \

trac/wiki/tests/formatter.py

         try:
             self.assertEquals(self.correct, v)
         except AssertionError, e:
-            raise AssertionError('%s\n\%s:%s: for the input '
+            raise AssertionError('%s\n%s:%s: for the input '
                                  '(formatter flavor was "%s")' \
                                  % (str(e), self.file, self.line,
                                     formatter.flavor))

trac/wiki/tests/wiki-tests.txt

 ==============================
 Add-on to changeset:123:
 Some change.
-
 ticket:1
 This ticket is the first one
+changeset:123>
 ------------------------------
 <p>
 Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
 Some change.
-</p>
-<p>
 <a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a>
 This ticket is the first one
+<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&gt;
 </p>
 ------------------------------
 Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>:
 Some change.
-
 <a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a>
 This ticket is the first one
+<a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>&gt;
 ==============================
 CamelCase AlabamA ABc AlaBamA FooBar
 ------------------------------
 </p>
 ------------------------------
 ==============================
+Test:[[BR]] There should be a line break
+
+Change:[10] There should be a link to changeset [10]
+
+Other test:'''bold text''' is not bold
+------------------------------
+<p>
+Test:<br /> There should be a line break
+</p>
+<p>
+Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a>
+</p>
+<p>
+Other test:<strong>bold text</strong> is not bold
+</p>
+------------------------------
+Test:  There should be a line break
+
+Change:<a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a> There should be a link to changeset <a class="missing changeset" href="/changeset/10" rel="nofollow">[10]</a>
+
+Other test:<strong>bold text</strong> is not bold
+==============================
 {{{
 Preformatted text.
 }}}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.