public static String cleanPath(String path) {
        if (!hasLength(path)) {
            return path;
        }
        
        String normalizedPath = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);
        String pathToUse = normalizedPath;
        
        // Shortcut if there is no work to do
        if (pathToUse.indexOf(DOT) == -1) {
            return pathToUse;
        }
        
        // Strip prefix from path to analyze, to not treat it as part of the
        // first path element. This is necessary to correctly parse paths like
        // "file:core/../core/io/Resource.class", where the ".." should just
        // strip the first "core" directory while keeping the "file:" prefix.
        int prefixIndex = pathToUse.indexOf(':');
        String prefix = "";
        if (prefixIndex != -1) {
            prefix = pathToUse.substring(0, prefixIndex + 1);
            if (prefix.contains(FOLDER_SEPARATOR)) {
                prefix = "";
            } else {
                pathToUse = pathToUse.substring(prefixIndex + 1);
            }
        }
        if (pathToUse.startsWith(FOLDER_SEPARATOR)) {
            prefix = prefix + FOLDER_SEPARATOR;
            pathToUse = pathToUse.substring(1);
        }
        
        String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
        // we never require more elements than pathArray and in the common case the same number
        Deque<String> pathElements = new ArrayDeque<>(pathArray.length);
        int tops = 0;
        
        for (int i = pathArray.length - 1; i >= 0; i--) {
            String element = pathArray[i];
            if (DOT.equals(element)) {
                // Points to current directory - drop it.
            } else if (TOP_PATH.equals(element)) {
                // Registering top path found.
                tops++;
            } else {
                if (tops > 0) {
                    // Merging path element with element corresponding to top path.
                    tops--;
                } else {
                    // Normal path element found.
                    pathElements.addFirst(element);
                }
            }
        }
        
        // All path elements stayed the same - shortcut
        if (pathArray.length == pathElements.size()) {
            return normalizedPath;
        }
        // Remaining top paths need to be retained.
        for (int i = 0; i < tops; i++) {
            pathElements.addFirst(TOP_PATH);
        }
        // If nothing else left, at least explicitly point to current path.
        if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) {
            pathElements.addFirst(DOT);
        }
        
        final String joined = collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
        // avoid string concatenation with empty prefix
        return prefix.isEmpty() ? joined : prefix + joined;
    }
@Test
    void testCleanPath() {
        // Test case 1: path with no length
        String path1 = "";
        String expected1 = "";
        assertEquals(expected1, StringUtils.cleanPath(path1));
        
        // Test case 2: normal path
        String path2 = "path/to/file";
        String expected2 = "path/to/file";
        assertEquals(expected2, StringUtils.cleanPath(path2));
        
        // Test case 3: path with Windows folder separator
        String path3 = "path\\to\\文件";
        String expected3 = "path/to/文件";
        assertEquals(expected3, StringUtils.cleanPath(path3));
        
        // Test case 4: path with dot
        String path4 = "path/..";
        String expected4 = "";
        assertEquals(expected4, StringUtils.cleanPath(path4));
        
        // Test case 5: path with top path
        String path5 = "path/../top";
        String expected5 = "top";
        assertEquals(expected5, StringUtils.cleanPath(path5));
        
        // Test case 6: path with multiple top path
        String path6 = "path/../../top";
        String expected6 = "../top";
        assertEquals(expected6, StringUtils.cleanPath(path6));
        
        // Test case 7: path with leading colon
        String path7 = "file:../top";
        String expected7 = "file:../top";
        assertEquals(expected7, StringUtils.cleanPath(path7));
        
        // Test case 8: path with leading slash
        String path8 = "file:/path/../file";
        String expected8 = "file:/file";
        assertEquals(expected8, StringUtils.cleanPath(path8));
        
        // Test case 9: path with empty prefix
        String path9 = "file:path/../file";
        String expected9 = "file:file";
        assertEquals(expected9, StringUtils.cleanPath(path9));
        
        // Test case 10: prefix contain separator
        String path10 = "file/:path/../file";
        String expected10 = "file/file";
        assertEquals(expected10, StringUtils.cleanPath(path10));
        
        // Test case 11: dot in file name
        String path11 = "file:/path/to/file.txt";
        String expected11 = "file:/path/to/file.txt";
        assertEquals(expected11, StringUtils.cleanPath(path11));
        
        // Test case 12: dot in path
        String path12 = "file:/path/./file.txt";
        String expected12 = "file:/path/file.txt";
        assertEquals(expected12, StringUtils.cleanPath(path12));
        
        // Test case 13: path with dot and slash
        String path13 = "file:aaa/../";
        String expected13 = "file:./";
        assertEquals(expected13, StringUtils.cleanPath(path13));
    }