StringUtil { public static boolean doesPathContainParentPathSegment( final String path ) { Matcher m = StringUtil.CONTAINS_PARENT_PATH_PATTERN.matcher( path ); return m.matches(); } private  StringUtil(); static String[] tokenStringToArray( final String tokenizedString, final String token ); static boolean doesPathContainParentPathSegment( final String path ); static void main( final String[] args ); static boolean isEmpty( final String str ); static String getMapAsPrettyString( final Map map ); static Map<String, String> trimStringMap( Map<String, String> map ); static List<String> trimStringList( List<String> list ); static String trimToEmpty( String string );  }
@Test public void testDoesPathContainParentPathSegment() { String[] matchStrings = { "../bart/maggie.xml", "/bart/..", "/bart/../maggie/homer.xml", ".. "/bart "/bart "/bart/judi" + '\0' + ".xml", "/../", "/..", "../", "..\\bart\\maggie.xml", "\\bart\\..", "\\bart\\" + '\0' + ".png", "\\bart\\..\\maggie\\homer.xml", ".." }; for ( String testString : matchStrings ) { boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertTrue( matches ); } String[] noMatchStrings = { "I am clean", "/go/not/parent.xml", "\\go\\not\\parent.xml", "should/not..not/match", "should/not%0Dnot/match", "..should/not/match.xml", "should/not..", "..." }; for ( String testString : noMatchStrings ) { boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertFalse( matches ); } }