Skip to content
This repository

fix Debug::getEscaper() never called at Debug::dump() when xdebug is loaded #5240

Closed
wants to merge 6 commits into from

3 participants

Abdul Malik Ikhsan Maks Matthew Weier O'Phinney
Abdul Malik Ikhsan

if we set Debug::setEscaper(new \Zend\Escaper\Escaper) before Debug::dump() and we have xdebug, the getEscaper() never called. added condition so getEscaper() will be called.

library/Zend/Debug/Debug.php
... ...
@@ -104,7 +104,7 @@ public static function dump($var, $label = null, $echo = true)
104 104
                     . PHP_EOL . $output
105 105
                     . PHP_EOL;
106 106
         } else {
107  
-            if (!extension_loaded('xdebug')) {
  107
+            if (!extension_loaded('xdebug') || null !== static::$escaper) {
1
Maks Collaborator
Maks3w added a note October 21, 2013

This breaks the lazy load of getEscaper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/ZendTest/Debug/DebugTest.php
... ...
@@ -94,4 +94,14 @@ public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
94 94
         $this->assertContains("</pre>", $result);
95 95
     }
96 96
 
  97
+    public function testDebugHaveEscaper()
  98
+    {
  99
+        $escaper = new \Zend\Escaper\Escaper;
1
Maks Collaborator
Maks3w added a note October 21, 2013

Import Escaper as use statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Abdul Malik Ikhsan

@Maks3w done. please let me know if something I missed, thanks ;)

Abdul Malik Ikhsan

@Maks3w I have updated this PR

library/Zend/Debug/composer.json
((7 lines not shown))
18 17
     },
19 18
     "suggest": {
20  
-        "ext/xdebug": "XDebug, for better backtrace output"
  19
+        "ext/xdebug": "XDebug, for better backtrace output",
1
Matthew Weier O'Phinney Owner

I'll change this to ext-xdebug on commit, as that's the proper format for extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney commented on the diff October 23, 2013
library/Zend/Debug/composer.json
((7 lines not shown))
18 17
     },
19 18
     "suggest": {
20  
-        "ext/xdebug": "XDebug, for better backtrace output"
  19
+        "ext/xdebug": "XDebug, for better backtrace output",
  20
+        "zendframework/zend-escaper": "To support escaped output"
2
Matthew Weier O'Phinney Owner

This also needs to be in a "require-dev" section, as it's necessary for tests.

@weierophinney done, I've added to require-dev also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney commented on the diff October 23, 2013
tests/ZendTest/Debug/DebugTest.php
@@ -94,4 +95,14 @@ public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
94 95
         $this->assertContains("</pre>", $result);
95 96
     }
96 97
 
  98
+    public function testDebugHaveEscaper()
  99
+    {
  100
+        $escaper = new Escaper;
  101
+        Debug::setEscaper($escaper);
  102
+
  103
+        $a = array("a" => "<script type=\"text/javascript\"");
  104
+        $result = Debug::dump($a, "LABEL", false);
  105
+        $this->assertContains("&lt;script type=&quot;text/javascript&quot;&quot;", $result);
3
Matthew Weier O'Phinney Owner

I actually get a test failure here -- the actual content is not escaped...

@weierophinney this work on my machine and on travis too.

@weierophinney any suggestion for it ? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney closed this in d86ebd6 October 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  library/Zend/Debug/Debug.php
@@ -104,7 +104,9 @@ public static function dump($var, $label = null, $echo = true)
104 104
                     . PHP_EOL . $output
105 105
                     . PHP_EOL;
106 106
         } else {
107  
-            if (!extension_loaded('xdebug')) {
  107
+            if (null !== static::$escaper) {
  108
+                $output = static::$escaper->escapeHtml($output);
  109
+            } elseif (!extension_loaded('xdebug')) {
108 110
                 $output = static::getEscaper()->escapeHtml($output);
109 111
             }
110 112
 
9  library/Zend/Debug/composer.json
@@ -13,11 +13,14 @@
13 13
     },
14 14
     "target-dir": "Zend/Debug",
15 15
     "require": {
16  
-        "php": ">=5.3.3",
17  
-        "zendframework/zend-escaper": "self.version"
  16
+        "php": ">=5.3.3"
  17
+    },
  18
+    "require-dev": {
  19
+        "zendframework/zend-escaper": "*"
18 20
     },
19 21
     "suggest": {
20  
-        "ext/xdebug": "XDebug, for better backtrace output"
  22
+        "ext/xdebug": "XDebug, for better backtrace output",
  23
+        "zendframework/zend-escaper": "To support escaped output"
21 24
     },
22 25
     "extra": {
23 26
         "branch-alias": {
11  tests/ZendTest/Debug/DebugTest.php
@@ -10,6 +10,7 @@
10 10
 namespace ZendTest;
11 11
 
12 12
 use Zend\Debug\Debug;
  13
+use Zend\Escaper\Escaper;
13 14
 
14 15
 /**
15 16
  * @group      Zend_Debug
@@ -94,4 +95,14 @@ public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
94 95
         $this->assertContains("</pre>", $result);
95 96
     }
96 97
 
  98
+    public function testDebugHaveEscaper()
  99
+    {
  100
+        $escaper = new Escaper;
  101
+        Debug::setEscaper($escaper);
  102
+
  103
+        $a = array("a" => "<script type=\"text/javascript\"");
  104
+        $result = Debug::dump($a, "LABEL", false);
  105
+        $this->assertContains("&lt;script type=&quot;text/javascript&quot;&quot;", $result);
  106
+    }
  107
+
97 108
 }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.