boolean pathMatches()

in aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/FilterChainManager.java [207:247]


    boolean pathMatches(final String target, final String mapping) {
        // easiest case, they are exactly the same
        if (target.toLowerCase(Locale.ENGLISH).equals(mapping.toLowerCase(Locale.ENGLISH))) {
            return true;
        }

        String finalTarget = target;
        String finalMapping = mapping;
        // strip first slash
        if (target.startsWith("/")) {
            finalTarget = target.replaceFirst("/", "");
        }
        if (mapping.startsWith("/")) {
            finalMapping = mapping.replaceFirst("/", "");
        }

        String[] targetParts = finalTarget.split(PATH_PART_SEPARATOR);
        String[] mappingParts = finalMapping.split(PATH_PART_SEPARATOR);

        // another simple case, the filter applies to everything
        if (mappingParts.length == 1 && mappingParts[0].equals("*")) {
            return true;
        }

        for (int i = 0; i < targetParts.length; i++) {
            if (mappingParts.length < i + 1) {
                // if we haven't matched anything yet we never will
                return false;
            }
            // the exact work doesn't match the and holder is not a wildcard
            if (!targetParts[i].equals(mappingParts[i])) {
                if (mappingParts[i].equals("*")) {
                    break;
                } else {
                    return false;
                }
            }
        }

        return true;
    }