<commit_before><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2017 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace OAuth2Framework\Component\Server\Util;

final class Uri
{
    /**
     * Checks if the URI matches one of stored URIs.
     *
     * @param string $uri                  The URI to check
     * @param array  $storedUris           A list of stored URIs
     * @param bool   $pathTraversalAllowed
     *
     * @return bool
     */
    public static function isRedirectUriAllowed(string $uri, array $storedUris, bool $pathTraversalAllowed = false): bool
    {
        // If storedUris is empty, assume invalid
        if (count($storedUris) === 0) {
            return false;
        }

        if (false === self::isAnUrlOrUrn($uri, $pathTraversalAllowed)) {
            return false;
        }

        foreach ($storedUris as $storedUri) {
            if (strcasecmp(mb_substr($uri, 0, mb_strlen($storedUri, '8bit'), '8bit'), $storedUri) === 0) {
                return true;
            }
        }

        return false;
    }

    /**
     * @param string $uri
     * @param bool   $pathTraversalAllowed
     *
     * @return bool
     */
    private static function isAnUrlOrUrn(string $uri, bool $pathTraversalAllowed): bool
    {
        if ('urn:' === mb_substr($uri, 0, 4, '8bit')) {
            if (false === self::checkUrn($uri)) {
                return false;
            }
        } else {
            if (false === self::checkUrl($uri, $pathTraversalAllowed)) {
                return false;
            }
        }

        return true;<commit_msg>Basic comparaison of uri vs stored uris<commit_after><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2017 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace OAuth2Framework\Component\Server\Util;

final class Uri
{
    /**
     * Checks if the URI matches one of stored URIs.
     *
     * @param string $uri                  The URI to check
     * @param array  $storedUris           A list of stored URIs
     * @param bool   $pathTraversalAllowed
     *
     * @return bool
     */
    public static function isRedirectUriAllowed(string $uri, array $storedUris, bool $pathTraversalAllowed = false): bool
    {
        // If storedUris is empty, assume invalid
        if (count($storedUris) === 0) {
            return false;
        }

        if (false === self::isAnUrlOrUrn($uri, $pathTraversalAllowed)) {
            return false;
        }

        return in_array($uri, $storedUris);
    }

    /**
     * @param string $uri
     * @param bool   $pathTraversalAllowed
     *
     * @return bool
     */
    private static function isAnUrlOrUrn(string $uri, bool $pathTraversalAllowed): bool
    {
        if ('urn:' === mb_substr($uri, 0, 4, '8bit')) {
            if (false === self::checkUrn($uri)) {
                return false;
            }
        } else {
            if (false === self::checkUrl($uri, $pathTraversalAllowed)) {
                return false;
            }
        }

        return true;
{'fraction_non_alphanumeric': 0.10980513454995361, 'fraction_numerical': 0.009279307145066501, 'mean_word_length': 1.908273381294964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '952477', 'n_tokens_mistral': 988, 'n_tokens_neox': 948, 'n_words': 278}