浏览代码

Push security fix for IP address.

Mark Scherer 9 年之前
父节点
当前提交
b9ff6fff06
共有 3 个文件被更改,包括 15 次插入19 次删除
  1. 3 13
      Lib/Utility/Utility.php
  2. 9 5
      Test/Case/View/Helper/FormatHelperTest.php
  3. 3 1
      View/Helper/FormatHelper.php

+ 3 - 13
Lib/Utility/Utility.php

@@ -145,20 +145,10 @@ class Utility {
 	public static function getClientIp($safe = true) {
 	public static function getClientIp($safe = true) {
 		if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
 		if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
 			$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
 			$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
+		} elseif (!$safe && env('HTTP_CLIENT_IP')) {
+			$ipaddr = env('HTTP_CLIENT_IP');
 		} else {
 		} else {
-			if (env('HTTP_CLIENT_IP')) {
-				$ipaddr = env('HTTP_CLIENT_IP');
-			} else {
-				$ipaddr = env('REMOTE_ADDR');
-			}
-		}
-
-		if (env('HTTP_CLIENTADDRESS')) {
-			$tmpipaddr = env('HTTP_CLIENTADDRESS');
-
-			if (!empty($tmpipaddr)) {
-				$ipaddr = preg_replace('/(?:,.*)/', '', $tmpipaddr);
-			}
+			$ipaddr = env('REMOTE_ADDR');
 		}
 		}
 		return trim($ipaddr);
 		return trim($ipaddr);
 	}
 	}

+ 9 - 5
Test/Case/View/Helper/FormatHelperTest.php

@@ -136,19 +136,23 @@ class FormatHelperTest extends MyCakeTestCase {
 	 */
 	 */
 	public function testFontIcon() {
 	public function testFontIcon() {
 		$result = $this->Format->fontIcon('signin');
 		$result = $this->Format->fontIcon('signin');
-		$expected = '<i class="fa-signin"></i>';
+		$expected = '<i class="fa fa-signin"></i>';
 		$this->assertEquals($expected, $result);
 		$this->assertEquals($expected, $result);
 
 
 		$result = $this->Format->fontIcon('signin', ['rotate' => 90]);
 		$result = $this->Format->fontIcon('signin', ['rotate' => 90]);
-		$expected = '<i class="fa-signin fa-rotate-90"></i>';
+		$expected = '<i class="fa fa-signin fa-rotate-90"></i>';
 		$this->assertEquals($expected, $result);
 		$this->assertEquals($expected, $result);
 
 
 		$result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted']]);
 		$result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted']]);
-		$expected = '<i class="fa-signin fa-muted fa-5x"></i>';
+		$expected = '<i class="fa fa-signin fa-muted fa-5x"></i>';
+		$this->assertEquals($expected, $result);
+
+		$result = $this->Format->fontIcon('asterisk', ['namespace' => 'glyphicon']);
+		$expected = '<i class="glyphicon glyphicon-asterisk"></i>';
 		$this->assertEquals($expected, $result);
 		$this->assertEquals($expected, $result);
 
 
 		$result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted'], 'namespace' => 'icon']);
 		$result = $this->Format->fontIcon('signin', ['size' => 5, 'extra' => ['muted'], 'namespace' => 'icon']);
-		$expected = '<i class="icon-signin icon-muted icon-5x"></i>';
+		$expected = '<i class="icon icon-signin icon-muted icon-5x"></i>';
 		$this->assertEquals($expected, $result);
 		$this->assertEquals($expected, $result);
 	}
 	}
 
 
@@ -504,7 +508,7 @@ class FormatHelperTest extends MyCakeTestCase {
 			$res = $this->Format->wordCensor($value, ['Arsch', 'Ficken', 'Bitch']);
 			$res = $this->Format->wordCensor($value, ['Arsch', 'Ficken', 'Bitch']);
 			$this->assertEquals($expected === null ? $value : $expected, $res);
 			$this->assertEquals($expected === null ? $value : $expected, $res);
 		}
 		}
-		
+
 		$input = 'dfssdfsdj sdkfj sdkfj ksdfj bitch ksdfj';
 		$input = 'dfssdfsdj sdkfj sdkfj ksdfj bitch ksdfj';
 		$result = $this->Format->wordCensor($input, ['Bitch'], '***');
 		$result = $this->Format->wordCensor($input, ['Bitch'], '***');
 		$expected = 'dfssdfsdj sdkfj sdkfj ksdfj *** ksdfj';
 		$expected = 'dfssdfsdj sdkfj sdkfj ksdfj *** ksdfj';

+ 3 - 1
View/Helper/FormatHelper.php

@@ -315,7 +315,9 @@ class FormatHelper extends TextHelper {
 		];
 		];
 		$options += $defaults;
 		$options += $defaults;
 		$icon = (array)$icon;
 		$icon = (array)$icon;
-		$class = [];
+		$class = [
+			$options['namespace']
+		];
 		foreach ($icon as $i) {
 		foreach ($icon as $i) {
 			$class[] = $options['namespace'] . '-' . $i;
 			$class[] = $options['namespace'] . '-' . $i;
 		}
 		}