<commit_before><?php
/*
 * Copyright 2017 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

class MY_Input extends CI_Input {
	public function post($key = null, $xss_clean = false) {
		$ret = parent::post($key, $xss_clean);
		if (is_array($ret) || is_object($ret)) {
			$data = [
				"key" => $key,
				"ret" => $ret
			];
			if (preg_match("/^[a-zA-Z0-9_\.-]+$/", $key)) {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input in field $key", $data);
			} else {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
			}
		}
		return $ret;
	}

	public function post_array($key) {
		$ret = parent::post($key);
		if (!is_array($ret)) {
			throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
		}
		return $ret;
	}
}<commit_msg>Fix error handling in MY_Input->post_array()<commit_after><?php
/*
 * Copyright 2017 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

class MY_Input extends CI_Input {
	public function post($key = null, $xss_clean = false) {
		$ret = parent::post($key, $xss_clean);
		if (is_array($ret) || is_object($ret)) {
			$data = [
				"key" => $key,
				"ret" => $ret
			];
			if (preg_match("/^[a-zA-Z0-9_\.-]+$/", $key)) {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input in field $key", $data);
			} else {
				throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
			}
		}
		return $ret;
	}

	public function post_array($key) {
		$ret = parent::post($key);
		if ($ret === false) {
			return false;
		} elseif (!is_array($ret)) {
			$data = [
				"key" => $key,
				"ret" => $ret
			];
			throw new \exceptions\UserInputException("input/invalid-form-field", "Invalid input", $data);
		}
		return $ret;
	}
}
{'fraction_non_alphanumeric': 0.18653648509763618, 'fraction_numerical': 0.007194244604316547, 'mean_word_length': 3.602836879432624, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '3840372', 'n_tokens_mistral': 792, 'n_tokens_neox': 698, 'n_words': 160}