当前位置: 首页>>代码示例>>PHP>>正文


PHP Codec::normalizeEncoding方法代码示例

本文整理汇总了PHP中Codec::normalizeEncoding方法的典型用法代码示例。如果您正苦于以下问题:PHP Codec::normalizeEncoding方法的具体用法?PHP Codec::normalizeEncoding怎么用?PHP Codec::normalizeEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Codec的用法示例。


在下文中一共展示了Codec::normalizeEncoding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: whitelist

 /**
  * Returns the supplied input string after removing any characters not
  * present in the supplied whitelist.
  *
  * @param string $input     string input to be filtered.
  * @param string $whitelist array or string of whitelist characters.
  *
  * @return string returns characters from $input that are present in $whitelist.
  */
 public function whitelist($input, $whitelist)
 {
     // Sanity check
     if (!is_string($input) || $input == '') {
         $input = '';
     }
     if (is_string($whitelist)) {
         $charEnc = Codec::detectEncoding($whitelist);
         $limit = mb_strlen($whitelist, $charEnc);
         $ary = array();
         for ($i = 0; $i < $limit; $i++) {
             $ary[] = mb_substr($whitelist, $i, 1, $charEnc);
         }
         $whitelist = $ary;
     }
     $filtered = '';
     $initialCharEnc = Codec::detectEncoding($input);
     $_4ByteCharacterString = Codec::normalizeEncoding($input);
     $limit = mb_strlen($_4ByteCharacterString, 'UTF-32');
     for ($i = 0; $i < $limit; $i++) {
         $c = mb_substr($_4ByteCharacterString, $i, 1, 'UTF-32');
         if (Codec::containsCharacter($c, $whitelist)) {
             $filtered .= $c;
         }
     }
     if ($filtered != '') {
         $filtered = mb_convert_encoding($filtered, $initialCharEnc, 'UTF-32');
     }
     if (!is_string($filtered)) {
         $filtered = '';
     }
     return $filtered;
 }
开发者ID:AnvilStriker,项目名称:owasp-esapi-php,代码行数:42,代码来源:BaseValidationRule.php

示例2: testUnixCodec

 /**
  * Test of UnixCodec
  */
 public function testUnixCodec()
 {
     $instance = ESAPI::getEncoder();
     $codec_unix = new UnixCodec();
     $this->assertEquals(null, $instance->encodeForOS($codec_unix, null));
     $decoded = $codec_unix->decodeCharacter(Codec::normalizeEncoding("n"));
     $this->assertEquals(null, $decoded['decodedCharacter']);
     $decoded = $codec_unix->decodeCharacter(Codec::normalizeEncoding(""));
     $this->assertEquals(null, $decoded['decodedCharacter']);
     $immune = array("");
     // not that it matters, but the java test would encode alphanums with such an immune param.
     $encoded = $codec_unix->encodeCharacter($immune, "<");
     $decoded = $codec_unix->decode($encoded);
     $this->assertEquals("<", $decoded);
     $orig = "/etc/passwd";
     $this->assertEquals($orig, $codec_unix->decode($orig));
     $immune = array();
     $orig = "/etc/passwd";
     $encoded = $codec_unix->encode($immune, $orig);
     $this->assertEquals($orig, $codec_unix->decode($encoded));
     // TODO: Check that this is acceptable for Unix hosts
     $this->assertEquals("c\\:\\\\jeff", $instance->encodeForOS($codec_unix, "c:\\jeff"));
     $this->assertEquals("c\\:\\\\jeff", $codec_unix->encode($immune, "c:\\jeff"));
     $this->assertEquals("dir\\ \\&\\ foo", $instance->encodeForOS($codec_unix, "dir & foo"));
     $this->assertEquals("dir\\ \\&\\ foo", $codec_unix->encode($immune, "dir & foo"));
     // Unix paths (that must be encoded safely)
     // TODO: Check that this is acceptable for Unix
     $this->assertEquals("\\/etc\\/hosts", $instance->encodeForOS($codec_unix, "/etc/hosts"));
     $this->assertEquals("\\/etc\\/hosts\\;\\ ls\\ -l", $instance->encodeForOS($codec_unix, "/etc/hosts; ls -l"));
     // these tests check that mixed character encoding is handled properly when encoding.
     $expected = '/^[a-zA-Z0-9\\/+]*={0,2}$/';
     for ($i = 0; $i < 256; $i++) {
         $input = chr($i);
         $output = $instance->encodeForBase64($input);
         $this->assertRegExp($expected, $output, "Input was character with ordinal: {$i} - %s");
         $this->assertEquals($input, $instance->decodeFromBase64($output));
     }
     for ($i = 0; $i < 256; $i++) {
         $input = 'a' . chr($i);
         $output = $instance->encodeForBase64($input);
         $this->assertRegExp($expected, $output, "Input was 'a' concat with character with ordinal: {$i} - %s");
         $this->assertEquals($input, $instance->decodeFromBase64($output));
     }
     for ($i = 0; $i < 256; $i++) {
         $input = 'ϑ' . chr($i);
         $output = $instance->encodeForBase64($input);
         $this->assertRegExp($expected, $output, "Input was char known as '&thetasym;' concat with character with ordinal: {$i} - %s");
         $this->assertEquals($input, $instance->decodeFromBase64($output));
     }
 }
开发者ID:najamelan,项目名称:PHP-ESAPI,代码行数:53,代码来源:EncoderTest.php


注:本文中的Codec::normalizeEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。