<commit_before><?php

class ApiDiscussionController extends DiscussionController
{
    /**
     * Get a single discussion.
     *
     * @param  int    $foreignId
     * @param  string $page
     *
     * @return void
     */
    public function getByForeignId($foreignId = '', $page = '')
    {
        // Load the discussion record
        $foreignId = ($this->isValidUuid($foreignId)) ? $foreignId : 0;
        if (!array_key_exists('Discussion', $this->Data)) {
            $this->setData('Discussion', $this->DiscussionModel->getForeignID($foreignId), true);
        }

        if (!is_object($this->Discussion)) {
            throw notFoundException('Discussion');
        }

        $this->index($this->Discussion->DiscussionID, '', $page);
    }

    /**
     * Checks that a string appears to be in the format of a UUID.
     *
     * @param  string $uuid
     *
     * @return bool
     */
    protected function isValidUuid($uuid)
    {
        $pattern = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}';

        return (bool) preg_match('/^'.$pattern.'$/', $uuid);
    }
}<commit_msg>Throws an exception with 400 bad request if id is not valid<commit_after><?php

class ApiDiscussionController extends DiscussionController
{
    /**
     * Get a single discussion.
     *
     * @param  int    $foreignId
     * @param  string $page
     *
     * @return void
     */
    public function getByForeignId($foreignId = '', $page = '')
    {
        if (!$this->isValidUuid($foreignId)) {
            throw new Gdn_UserException('Bad Request', 400);
        }

        if (!array_key_exists('Discussion', $this->Data)) {
            $this->setData('Discussion', $this->DiscussionModel->getForeignID($foreignId), true);
        }

        if (!is_object($this->Discussion)) {
            throw notFoundException('Discussion');
        }

        $this->index($this->Discussion->DiscussionID, '', $page);
    }

    /**
     * Checks that a string appears to be in the format of a UUID.
     *
     * @param  string $uuid
     *
     * @return bool
     */
    protected function isValidUuid($uuid)
    {
        $pattern = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}';

        return (bool) preg_match('/^'.$pattern.'$/', $uuid);
    }
}
{'fraction_non_alphanumeric': 0.16198125836680052, 'fraction_numerical': 0.012940651494868362, 'mean_word_length': 2.2492753623188406, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2015369', 'n_tokens_mistral': 723, 'n_tokens_neox': 682, 'n_words': 146}