<commit_before><?php
/**
 * OWASP Enterprise Security API (ESAPI)
 *
 * This file is part of the Open Web Application Security Project (OWASP)
 * Enterprise Security API (ESAPI) project. For details, please see
 * <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
 *
 * Copyright (c) 2009 The OWASP Foundation
 *
 * The ESAPI is published by OWASP under the BSD license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 *
 * @author <NAME> < van der aj ( at ) owasp. org >
 * @created 2009
 */

require_once dirname(__FILE__).'/../../src/ESAPI.php';
require_once dirname(__FILE__).'/../../src/codecs/PercentCodec.php';

class PercentCodecTest extends UnitTestCase
{
	private $percentCodec = null;
	
	function setUp()
	{
		global $ESAPI;

		if ( !isset($ESAPI))
		{
			$ESAPI = new ESAPI();
		}
		
		$this->percentCodec = new PercentCodec();
	}

	function tearDown()
	{

	}
	
	function testEncode()
	{
		$immune = array("/");
		
		$this->assertEqual( '%22%3B%20ls%20/%20%3E%20/tmp/foo%3B%20%23%20', $this->percentCodec->encode($immune, '"; ls / > /tmp/foo; # ') );
	}
	
	function testEncodeCharacter()
	{
		$immune = array("");
		
		$this->assertEqual( "%3C", $this->percentCodec->encode($immune, "<") );
	}	
	
	function testDecode()
	{
		$this->assertEqual( '"; ls / > /tmp/foo; # ', $this->percentCodec->decode('%22%3B%20ls%20/%20%3E%20/tmp/foo%3B%20%23%20') );
	}
		
	function testDecodeCharacter()
	{
		$this->assertEqual( "<", $this->percentCodec->decode("%3C") );
	}
	
}
?><commit_msg>Modified testEncode(). PercentCodec now encodes spaces to '+'. Added testDecodePlus() which tests the decoding of '+'.<commit_after><?php
/**
 * OWASP Enterprise Security API (ESAPI)
 *
 * This file is part of the Open Web Application Security Project (OWASP)
 * Enterprise Security API (ESAPI) project. For details, please see
 * <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
 *
 * Copyright (c) 2009 The OWASP Foundation
 *
 * The ESAPI is published by OWASP under the BSD license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 *
 * @author <NAME> < van der aj ( at ) owasp. org >
 * @created 2009
 */

require_once dirname(__FILE__).'/../../src/ESAPI.php';
require_once dirname(__FILE__).'/../../src/codecs/PercentCodec.php';

class PercentCodecTest extends UnitTestCase
{
	private $percentCodec = null;
	
	function setUp()
	{
		global $ESAPI;

		if ( !isset($ESAPI))
		{
			$ESAPI = new ESAPI();
		}
		
		$this->percentCodec = new PercentCodec();
	}

	function tearDown()
	{

	}
	
	function testEncode()
	{
		$immune = array("/");
		
		$this->assertEqual( '%22%3B+ls+/+%3E+/tmp/foo%3B+%23+', $this->percentCodec->encode($immune, '"; ls / > /tmp/foo; # ') );
	}
	
	function testEncodeCharacter()
	{
		$immune = array("");
		
		$this->assertEqual( "%3C", $this->percentCodec->encode($immune, "<") );
	}	
	
	function testDecode()
	{
		$this->assertEqual( '"; ls / > /tmp/foo; # ', $this->percentCodec->decode('%22%3B%20ls%20/%20%3E%20/tmp/foo%3B%20%23%20') );
	}
		
	function testDecodePlus()
	{
		$this->assertEqual( '"; ls / > /tmp/foo; # ', $this->percentCodec->decode('%22%3B+ls+/+%3E+/tmp/foo%3B+%23+') );
	}
		
	function testDecodeCharacter()
	{
		$this->assertEqual( "<", $this->percentCodec->decode("%3C") );
	}
	
}
?>
{'fraction_non_alphanumeric': 0.18251057827926656, 'fraction_numerical': 0.025669957686882933, 'mean_word_length': 3.1473684210526316, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7369728', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1222, 'n_words': 262}