rehamaltamimi / gwtwiki

Automatically exported from code.google.com/p/gwtwiki
0 stars 0 forks source link

Image links that have intra-page link are broken. #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an intra-page link in an Image tag in the wiki markup like this:
[[Image:skull.jpg|link=sandbox:createNewPage#Section Three]]

The basic problem is that the "#" character is getting URL encoded, and
should not.

What is the expected output?
sandbox:createNewPage#Section_Three

What do you see instead?
sandbox:createNewPage%23Section_Three

What version of the product are you using? On what operating system?
3.0.13

Please provide any additional information below.
To fix this problem, I overrode AbstractWikiModel.encodeTitleToUrl() like this:

    private static final String SPLIT_INTRA_PAGE_URL_RE = "^([^#]+)#?(.*)$";
    public static final Pattern SPLIT_INTRA_PAGE_URL_PATTERN =
Pattern.compile( SPLIT_INTRA_PAGE_URL_RE );

    @Override
    public String encodeTitleToUrl(String wikiTitle, boolean
firstCharacterAsUpperCase) {

        String encodedUrl;
        Matcher m = SPLIT_INTRA_PAGE_URL_PATTERN.matcher( wikiTitle );
        if ( m.matches() ) {
            // wikiTitle, which is a partial URL, contains an intra-page link (like
this: docs:page-name#intr-page-link)
            String lhs = m.group( 1 );
            String rhs = m.group( 2 );
            if ( StringUtils.isEmpty( rhs ) ) {
                encodedUrl = Encoder.encodeTitleToUrl(lhs, firstCharacterAsUpperCase );
            } else {
                encodedUrl = Encoder.encodeTitleToUrl(lhs, firstCharacterAsUpperCase )
+ "#" + Encoder.encodeTitleToUrl(rhs, firstCharacterAsUpperCase );
            }
        } else {
            encodedUrl = Encoder.encodeTitleToUrl(wikiTitle,
firstCharacterAsUpperCase );
        }
        return encodedUrl;
    }

Original issue reported on code.google.com by steven.b...@gmail.com on 2 Dec 2009 at 5:01

GoogleCodeExporter commented 8 years ago

Original comment by axelclk@gmail.com on 4 Dec 2009 at 4:35

GoogleCodeExporter commented 8 years ago
Fixed with: http://code.google.com/p/gwtwiki/source/detail?r=532

Original comment by axelclk@gmail.com on 4 Dec 2009 at 5:18