Edgewall Software
Modify

Opened 14 years ago

Closed 14 years ago

#2240 closed defect (fixed)

leading colon breaks wiki syntax

Reported by: vittorio@… Owned by: Christian Boos
Priority: high Milestone: 0.9
Component: wiki system Version: devel
Severity: major Keywords:
Cc: vittorio@… Branch:
Release Notes:
API Changes:

Description

A leading colon breaks some (maybe all) wiki syntax.

Some Tests:

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

Output:

Test:
There should be a line break

Change:[10] There should be a link to [10]

Other test:bold text is not bold

tested using trunk r2385, python 2.3.5, mod_python

Attachments (2)

escape_shref.patch (2.9 KB ) - added by Christian Boos 14 years ago.
Use "!" before a TracLinks for escaping the link (second version, small fix)
escape_shref.2.patch (3.0 KB ) - added by Christian Boos 14 years ago.
Take two, adding as a special case link:[[BR]] to translate to link:<br /> without the need of "!"

Download all attachments as: .zip

Change History (8)

comment:1 by Christian Boos, 14 years ago

Owner: changed from Jonas Borgström to Christian Boos
Status: newassigned

Well, this is the syntax for TracLinks. With the current trunk, the example you gave don't make sense as links, but with InterTrac / InterWiki, they will:

  • with InterTrac, what comes after the ":" is meant to be a shorthand to some object in the system. So Change:[10] would be interpreted as changeset 10 in the project named Change.
  • with InterWiki, what comes after the ":" is simply appended to the URL corresponding to the InterWiki prefix. It's even possible to have multiple colon-separated arguments and have them replaced in arbitrary position in the URL (see #1414). So Test:[[BR]] could be a valid InterWiki link.
  • lastly, test:'''...''' is interpreted as a link to test:'' followed by '...''', because single quotes (or double quotes) are use to quote target with embedded spaces.

That being said, there should be an easy way to escape those constructs.

I would propose to use the "!" prefix before what would otherwise look like a link prefix:

!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

by Christian Boos, 14 years ago

Attachment: escape_shref.patch added

Use "!" before a TracLinks for escaping the link (second version, small fix)

comment:2 by Christian Boos, 14 years ago

The attachment:escape_shref.patch implements the previous idea, and also enables the escaping of TracLinks with title, e.g.:

![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]

comment:3 by Christian Boos, 14 years ago

Careful readers might have caught the two errors in my examples above… Well, I got the unit-tests right, at least :)

Need to work on #454

by Christian Boos, 14 years ago

Attachment: escape_shref.2.patch added

Take two, adding as a special case link:[[BR]] to translate to link:<br /> without the need of "!"

comment:4 by Christian Boos, 14 years ago

Take three, this time on top of r2399:

  • tests/wiki-tests.txt

     
    357357</p>
    358358------------------------------
    359359==============================
     360Test:[[BR]] There should be a line break
     361
     362Change:[10] There should be a link to changeset [10]
     363
     364Other test:'''bold text''' is not bold
     365------------------------------
     366<p>
     367Test:<br /> There should be a line break
     368</p>
     369<p>
     370Change:<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>
     371</p>
     372<p>
     373Other test:<strong>bold text</strong> is not bold
     374</p>
     375------------------------------
     376Test:  There should be a line break
     377
     378Change:<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>
     379
     380Other test:<strong>bold text</strong> is not bold
     381==============================
    360382{{{
    361383Preformatted text.
    362384}}}
  • formatter.py

     
    137137
    138138    QUOTED_STRING = r"'[^']+'|\"[^\"]+\""
    139139
     140    SHREF_TARGET_FIRST = r"[\w/?!#@]"
    140141    SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])|&(?!lt;)|[^|&\s])"
    141     SHREF_TARGET_LAST_CHAR = r"[^|'~_\.,&\s\)\]:?!]"
     142    SHREF_TARGET_LAST = r"[a-zA-Z0-9/=]" # we don't want "_"
    142143
    143144    LHREF_RELATIVE_TARGET = r"[/.][^\s[\]]*"
    144145
     
    163164
    164165    _post_rules = [
    165166        # shref corresponds to short TracLinks, i.e. sns:stgt
    166         r"(?P<shref>((?P<sns>%s):(?P<stgt>%s|%s*%s)))" \
     167        r"(?P<shref>((?P<sns>%s):(?P<stgt>%s|%s(?:%s*%s)?)))" \
    167168        % (LINK_SCHEME, QUOTED_STRING,
    168            SHREF_TARGET_MIDDLE, SHREF_TARGET_LAST_CHAR),
     169           SHREF_TARGET_FIRST, SHREF_TARGET_MIDDLE, SHREF_TARGET_LAST),
    169170        # lhref corresponds to long TracLinks, i.e. [lns:ltgt label?]
    170171        r"(?P<lhref>\[(?:(?P<lns>%s):(?P<ltgt>%s|[^\]\s]*)|(?P<rel>%s))"
    171172        r"(?:\s+(?P<label>%s|[^\]]+))?\])" \

For the rational about the SHREF_TARGET_LAST, see related #1153.

comment:5 by vittorio@…, 14 years ago

using trunk r2400 patched with Ticket #1153: shref_fixes_r2399.patch, the three tests in the ticket description do work again! i couldnt find a problem when playing a bit with wiki and this patch.

comment:6 by Christian Boos, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r2401.

I'll reuse and update the attachment:escape_shref.2.patch for fixing #2251

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.