/** * Creates a DefaultSchemeParser with a {@link DefaultPathCanonizer} that uses that uses the operating system's * default path separator as the path separator and no tilde replacement. * If <code>parseQuery</code> is <code>true</code>, any query part (delimited by '?') will be parsed as such, * or considered as part of the path otherwise. * * @param parseQuery <code>true</code>, any query part (delimited by '?') will be parsed as such, or considered * as part of the path otherwise */ public DefaultSchemeParser(boolean parseQuery) { this(new DefaultPathCanonizer(System.getProperty("file.separator"), null), parseQuery); }
/** * Tests '.' and '..' factoring and tilde replacement if <code>tildeReplacement</code> is not <code>null</code>. * * @param separator path separator * @param tildeReplacement string to replace '~' path fragments with */ private void testCanonizer(String separator, String tildeReplacement) { DefaultPathCanonizer canonizer = new DefaultPathCanonizer(separator, tildeReplacement); // Test '~' canonization (or the lack thereof) if(tildeReplacement==null) { assert "~".equals(canonizer.canonize("~")); assert ("~"+separator+"blah").equals(canonizer.canonize("~"+separator+"blah")); } else { assert tildeReplacement.equals(canonizer.canonize("~")); assert (tildeReplacement+separator+"blah").equals(canonizer.canonize("~"+separator+"blah")); } // Test '.' and '..' factoring assert separator.equals(canonizer.canonize(getNormalizedPath("/home/maxence/../..", separator))); assert getNormalizedPath("/home/", separator).equals(canonizer.canonize(getNormalizedPath("/home/maxence/..", separator))); assert getNormalizedPath("/home/maxence/", separator).equals(canonizer.canonize(getNormalizedPath("/home/maxence/.", separator))); assert separator.equals(canonizer.canonize(getNormalizedPath("/home/maxence/../..", separator))); assert getNormalizedPath("/home/maxence/", separator).equals(canonizer.canonize(getNormalizedPath("/home//maxence//", separator))); assert separator.equals(canonizer.canonize(getNormalizedPath("/././.", separator))); assert "".equals(canonizer.canonize(getNormalizedPath("/../../..", separator))); assert separator.equals(canonizer.canonize(getNormalizedPath("/1/.././1/./2//./.././../", separator))); }