public static boolean isCanonicalizedPath()

in plugin/src/com/microsoft/alm/plugin/versioncontrol/path/ServerPath.java [267:331]


    public static boolean isCanonicalizedPath(final String serverItem, final boolean allowSemicolon) {
        if (serverItem.length() > MAX_SERVER_PATH_SIZE) {
            return false;
        }

        // The path is not legal if it does not start with $/.
        if (!serverItem.startsWith(ROOT)) {
            return false;
        }

        // If the path is $/, it is legal.
        if (2 == serverItem.length()) {
            return true;
        }

        // The path is not legal if it ends with a separator character.
        if (serverItem.length() > 2 && serverItem.charAt(serverItem.length() - 1) == PREFERRED_SEPARATOR_CHARACTER) {
            return false;
        }

        int pathPartLength = 0;

        for (int i = 2; i < serverItem.length(); i++) {
            final char c = serverItem.charAt(i);

            if (c == PREFERRED_SEPARATOR_CHARACTER) {
                if (!isCanonicalizedPathPart(serverItem, i, pathPartLength)) {
                    return false;
                }

                pathPartLength = 0;
                continue;
            }

            // The $ character is not permitted to lead a path part.
            if (0 == pathPartLength && c == ROOT.charAt(0)) {
                return false;
            }

            // Look up each character in the NTFS valid characters truth table.
            if (!FileHelper.isValidNTFSFileNameCharacter(c)) {
                return false;
            }

            // The semicolon character is not legal anywhere in a version
            // control path.
            if (!allowSemicolon && c == ';') {
                return false;
            }

            // Wildcard characters are not legal in a version control path.
            if (c == '*' || c == '?') {
                return false;
            }

            pathPartLength++;
        }

        // Check the last path part.
        if (!isCanonicalizedPathPart(serverItem, serverItem.length(), pathPartLength)) {
            return false;
        }

        return true;
    }