jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "szymon kuzniak" <skuzniak.cognif...@wp.pl>
Subject Encoded/Decoded problem
Date Tue, 05 Sep 2006 07:08:15 GMT
Hello guys,
I am working with JCR, and found a little deficiency. Let me explain on example - running
this simple program causes an exception:

class test {
    public static void main(String args[]) {
        String encoded = ISO9075.encode("$String");

exception is StringIndexOutOfBoundsException.

The problem isn't really in bad implementation, but in wrong use of Matcher.appendReplacement()
method. This function must have the dolar sign ($) and backslash (\) escaped with backslash.
But in current implementation all characters are passed to this function unescaped, what causes
mentioned exception when decoded string has dollars or backslashes. Hope fixing this will
not be a big deal.

Best Regards

Szymon Kuzniak

P.S. this is my implementation of decode() method.
    public static String decode(String name) {
        // quick check
        if (name.indexOf("_x") < 0) {
            // not encoded
            return name;
        StringBuffer decoded = new StringBuffer();
        Matcher m = ENCODE_PATTERN.matcher(name);
        while (m.find()) {
            String sign = Character.toString((char) Integer.parseInt(m.group().substring(2,
6), 16));
            if ("$".equals(sign) || "\\".equals(sign)) {
        	sign = "\\"+ sign;        			
            m.appendReplacement(decoded, sign);
        return decoded.toString();

Bierz ile chcesz! Nawet 50000 zł bez wizyty w banku.
Rata od 35 zł. Wniosek i decyzja przez telefon. Kliknij i sprawdź:

View raw message