public static void main( final String[] args ) { String[] testStrings = { "../bart/maggie.xml", "/bart/..", "/bart/../maggie/homer.xml", "..//bart/maggie.xml", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "/bart//..", "/bart//../maggie/homer.xml", "/../", "/..", "../", "..\\bart\\maggie.xml", "\\bart\\..", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ "\\bart\\..\\maggie\\homer.xml", "I am clean", "/go/not/parent.xml", "\\go\\not\\parent.xml", "..", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ "should/not..not/match", "..should/not/match.xml", "should/not..", "..." }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ for ( String testString : testStrings ) { boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); if ( matches ) { System.out.println( testString + " matches." ); //$NON-NLS-1$ } else { System.out.println( "--------" + testString + " DOES NOT MATCH." ); //$NON-NLS-1$//$NON-NLS-2$ } } }
boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertTrue( matches ); boolean matches = StringUtil.doesPathContainParentPathSegment( testString ); Assert.assertFalse( matches );