Changeset 1377

Show
Ignore:
Timestamp:
2008-01-20 18:59:56 (9 months ago)
Author:
mosipov
Message:

Added method and testcases to validate path

Location:
FCKeditor.Java/branches/2.4/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java

    r1361 r1377  
    114114        String typeStr = request.getParameter("Type"); 
    115115        String currentFolderStr = request.getParameter("CurrentFolder"); 
    116  
     116        boolean validPath = Utils.isValidPath(currentFolderStr); 
    117117        // TODO untersuchen wie es vom Res Browser kommt 
    118118        String currentPath = constructTypeBasedFolderString(typeStr, currentFolderStr); 
     
    121121        File currentDir = new File(currentDirPath); 
    122122        if (!currentDir.exists()) { 
    123             currentDir.mkdir(); 
     123            currentDir.mkdirs(); 
    124124            logger.debug("Dir successfull created: " + currentDirPath); 
    125125        } 
  • FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/tool/Utils.java

    r1375 r1377  
    2424import java.util.Set; 
    2525import java.util.StringTokenizer; 
     26 
     27import org.apache.commons.io.FilenameUtils; 
    2628 
    2729/** 
     
    119121 
    120122        // TODO code isn't very beautiful, is there a better way besides looping through the filename? 
    121         static String forceSingleExtension (final String filename) { 
     123        public static String forceSingleExtension (final String filename) { 
    122124                 
    123125                int lastDotPosition = filename.lastIndexOf("."); 
     
    129131        } 
    130132 
    131         static boolean isSingleExtension (final String filename) { 
     133        public static boolean isSingleExtension (final String filename) { 
    132134                 
    133135                return filename.matches("[^\\.]+\\.[^\\.]+"); 
    134136                 
    135137        } 
     138         
     139        public static boolean isValidPath (final String path) { 
     140                 
     141                if (isEmpty(path)) 
     142                        return false; 
     143                 
     144                if (!path.startsWith("/")) 
     145                        return false; 
     146                 
     147                if (isEmpty(FilenameUtils.normalize(path))) 
     148                        return false; 
     149                 
     150                return true; 
     151        } 
    136152} 
  • FCKeditor.Java/branches/2.4/src/test/java/net/fckeditor/tool/UtilsTest.java

    r1375 r1377  
    146146                assertEquals("hacked_.txt", actual); 
    147147        } 
     148         
     149        @Test 
     150        public void isValidPath01 () { 
     151                String path = ""; 
     152                boolean condition = !Utils.isValidPath(path); 
     153                assertTrue(condition); 
     154        } 
     155        @Test 
     156        public void isValidPath02 () { 
     157                String path = "/"; 
     158                boolean condition = Utils.isValidPath(path); 
     159                assertTrue(condition); 
     160        } 
     161         
     162        @Test 
     163        public void isValidPath03 () { 
     164                String path = "/./"; 
     165                boolean condition = Utils.isValidPath(path); 
     166                assertTrue(condition); 
     167        } 
     168         
     169        @Test 
     170        public void isValidPath04 () { 
     171                String path = "/newf/.."; 
     172                boolean condition = Utils.isValidPath(path); 
     173                assertTrue(condition); 
     174        } 
     175         
     176        @Test 
     177        public void isValidPath05 () { 
     178                String path = "/../"; 
     179                boolean condition = !Utils.isValidPath(path); 
     180                assertTrue(condition); 
     181        } 
     182         
     183        @Test 
     184        public void isValidPath06 () { 
     185                String path = "/stuff/../.."; 
     186                boolean condition = !Utils.isValidPath(path); 
     187                assertTrue(condition); 
     188        } 
     189         
     190        @Test 
     191        public void isValidPath07 () { 
     192                String path = "/my/stuff/.."; 
     193                boolean condition = Utils.isValidPath(path); 
     194                assertTrue(condition); 
     195        } 
    148196}