Changeset 4927


Ignore:
Timestamp:
May 13, 2009, 11:22:41 AM (13 years ago)
Author:
Martin Svensson
Message:

Fixes #1307 File view fails if a file name contains non-ascii characters

Location:
branches/2.11-stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.11-stable/src/core/net/sf/basedb/core/Path.java

    r4517 r4927  
    2323package net.sf.basedb.core;
    2424
     25import java.io.UnsupportedEncodingException;
     26import java.net.URLEncoder;
    2527import java.util.regex.Pattern;
    2628
     
    283285    return sb.toString();
    284286  }
     287 
     288  /**
     289    Get this Path's URL-string encoded with a given
     290    character encoding.
     291   
     292    @param enc The encoding to use. UTF-8 is used is this is null.
     293    @return The encoded URL-string.
     294      @throws UnsupportedEncodingException If the give encoding is not supported
     295      @since 2.11.1
     296   */
     297  public String toURLString(String enc)
     298    throws UnsupportedEncodingException
     299  {
     300    StringBuilder sb = new StringBuilder();
     301    enc = (enc == null || enc.length() == 0) ? "UTF-8" : enc;
     302    if (userlogin != null)
     303    {
     304      sb.append("~").append(URLEncoder.encode(userlogin, enc));
     305    }
     306    for (String directory : directories)
     307    {
     308      sb.append("/").append(URLEncoder.encode(directory, enc));
     309    }
     310    if (filename != null && getType() == Type.FILE)
     311    {
     312      sb.append("/").append(URLEncoder.encode(filename, enc));
     313    }
     314    if (sb.length() == 0) sb.append("/"); // For the root directory
     315    return sb.toString();
     316  }
    285317
    286318  /**
  • branches/2.11-stable/www/filemanager/files/index.jsp

    r4587 r4927  
    465465    dc = sc.newDbControl();
    466466    File f = File.getById(dc, cc.getId());
    467     redirect = root + "filemanager/files/view/-"+ID+"-"+HTML.urlEncode(f.getPath().toString());
     467    redirect = root + "filemanager/files/view/-"+ID+"-"+ f.getPath().toURLString("UTF-8");
    468468    dc.close();
    469469  }
  • branches/2.11-stable/www/filemanager/index.jsp

    r4510 r4927  
    8989    dc = sc.newDbControl();
    9090    File f = File.getById(dc, cc.getId());
    91     redirect = root + "filemanager/files/view/-"+ID+"-"+HTML.urlEncode(f.getPath().toString());
     91    redirect = root + "filemanager/files/view/-"+ID+"-"+ f.getPath().toURLString("UTF-8");
    9292    dc.close();
    9393  }
Note: See TracChangeset for help on using the changeset viewer.