<commit_before><?php

namespace Crackle\Requests\Fields {

	use \InvalidArgumentException;

	/**
	 * Represents the GET parameters of a request.
	 * @author <NAME>
	 */
	class Parameters extends Fields {

		/**
		 * Retrieve the GET parameters as a query string.
		 * @return string			The parameters formatted as a query string.
		 */
		public function getQueryString() {
			// Crackle permits duplicate keys, so we cannot use PHP's http_build_query()
			$parts = array();
			foreach($this->getPairs() as $pair) {
				$parts[] = urlencode($pair->getKey()) . '=' . urlencode($pair->getValue());
			}
			return implode('&', $parts);
		}

		/**
		 * Import any GET parameters in a URL.
		 * @param string $url					The URL to parse.
		 * @throws InvalidArgumentException		If the URL provided couldn't be parsed.
		 * @return string						The inputted URL, without query string (if it had one).
		 */
		public function parse($url) {
			$parts = parse_url($url);
			if($parts === false) {
				throw new InvalidArgumentException('The supplied URL is invalid.');
			}

			if(isset($parts['query'])) {
				// extract GET parameters and add them as fields
				$params = array();
				parse_str($parts['query'], $params);
				foreach($params as $name => $value) {
					$this->add($name, $value);
				}
			}

			// if the URL contains a host with no trailing slash, this key will not exist
			if(!isset($parts['path'])) {
				$parts['path'] = '';
			}

			// return the original URL without the parameters
			return sprintf('%s://%s%s', $parts['scheme'], $parts['host'], $parts['path']);
		}
	}
}<commit_msg>Implemented a more liberal version of parse_url().<commit_after><?php

namespace Crackle\Requests\Fields {

	use \InvalidArgumentException;

	/**
	 * Represents the GET parameters of a request.
	 * @author <NAME>
	 */
	class Parameters extends Fields {

		/**
		 * Retrieve the GET parameters as a query string.
		 * @return string			The parameters formatted as a query string.
		 */
		public function getQueryString() {
			// Crackle permits duplicate keys, so we cannot use PHP's http_build_query()
			$parts = array();
			foreach($this->getPairs() as $pair) {
				$parts[] = urlencode($pair->getKey()) . '=' . urlencode($pair->getValue());
			}
			return implode('&', $parts);
		}

		/**
		 * Import any GET parameters in a URL.
		 * @param string $url					The URL to parse.
		 * @throws InvalidArgumentException		If the URL provided couldn't be parsed.
		 * @return string						The inputted URL, without query string (if it had one).
		 */
		public function parse($url) {
			$parts = parse_url($url);
			if($parts === false) {
				throw new InvalidArgumentException('The supplied URL is invalid.');
			}

			if(isset($parts['query'])) {
				// extract GET parameters and add them as fields
				$this->import($parts['query']);
			}

			// if the URL contains a host with no trailing slash, this key will not exist
			if(!isset($parts['path'])) {
				$parts['path'] = '';
			}

			// return the original URL without the parameters
			return sprintf('%s://%s%s', $parts['scheme'], $parts['host'], $parts['path']);
		}

		/**
		 * Parses a query string, importing all parameters. Similar to parse_url() without its quirks.
		 * @param string $string					The query string to parse and import.
		 * @throws InvalidArgumentException			If the query string is very malformed.
		 */
		private final function import($string) {
			foreach(explode('&', $string) as $part) {
				$equals = strpos($part, '=');

				if($equals === false) { // minimal validation - we don't check there's only 1 '=' etc.
					throw new InvalidArgumentException('Malformed query string.');
				}

				$this->add(
						urldecode(substr($part, 0, $equals)), // name
						urldecode(substr($part, $equals + 1))); // value
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.14541622760800843, 'fraction_numerical': 0.0007903055848261328, 'mean_word_length': 3.1588170865279297, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4486959', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1086, 'n_words': 378}