Wiki

Clone wiki

BibSonomy / development / modules / webapp / UrlRewriteFilter

We are using the UrlRewriteFilter to enable BibSonomy to use nice URLs, e.g., http://www.bibsonomy.org/user/jaeschke/web instead of http://www.bibsonomy.org/user?requestedUser=jaeschke&requestedTags=web. The filter thus is a central part of the web application and changes to its config file should be done very carefully and after talking to senior staff.

Issues

There are currently two issues with the URLRewriteFilter:

  • issue #12 with URLs containing backslashes
  • issue #13 with URLs containing encoded slashes

Modifications

Currently, we are using the version 3.2.0_jaeschke which is a modification to work around an encoding bug.

In the class org.tuckey.web.filters.urlrewrite.functions.StringFunctions the functions escape and unescape were modified in the following way:

from

public static String escape(String subject) {
    String encoding = "UTF-8";
    if ( FIND_COLON_PATTERN.matcher(subject).find()) {
        encoding = subject.substring(0, subject.indexOf(':'));
        subject = subject.substring(subject.indexOf(':')+1);
    }
    try {
        return URLEncoder.encode(subject, encoding);
    } catch (UnsupportedEncodingException e) {
        log.error(e, e);
    }
    return "";
}

to

public static String escape(String subject) {
    try {
        if ( FIND_COLON_PATTERN.matcher(subject).find()) {
            String encoding = subject.substring(0, subject.indexOf(':'));
            return URLEncoder.encode(subject.substring(subject.indexOf(':')+1), encoding);
        }
    } catch (UnsupportedEncodingException e) {
        log.debug("String to escape contained unknown encoding, falling back to UTF-8", e);
    }
    try {
        return URLEncoder.encode(subject, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.error(e, e);
    }
    return "";
}

and from

public static String unescape(String subject) {
    String encoding = "UTF-8";
    if ( FIND_COLON_PATTERN.matcher(subject).find()) {
        subject = subject.substring(0, subject.indexOf(':'));
        encoding = subject.substring(subject.indexOf(':')+1);
    }
    try {
        return URLDecoder.decode(subject, encoding);
    } catch (UnsupportedEncodingException e) {
        log.error(e, e);
    }
    return "";
}

to

public static String unescape(String subject) {
    try {
        if ( FIND_COLON_PATTERN.matcher(subject).find()) {
            String encoding = subject.substring(0, subject.indexOf(':'));
            return URLDecoder.decode(subject.substring(subject.indexOf(':') + 1), encoding);
        }
    } catch (UnsupportedEncodingException e) {
        log.debug("String to unescape contained unknown encoding, falling back to UTF-8", e);
    }
    try {
        return URLDecoder.decode(subject, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.error(e, e);
    }
    return "";
}

Migration

In principle, it would be good to update to a more recent version. However, the config file format likely has changed and therefore this requires some effort. Before releasing the updated rules, good testing is crucial!

Updated