Development

#7596 (Catching exception thrown by a component = no CSS nor Javascript loaded)

You must first sign up to be able to contribute.

Ticket #7596 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

Catching exception thrown by a component = no CSS nor Javascript loaded

Reported by: naholyr Assigned to: fabien
Priority: major Milestone: 1.2.10
Component: view Version: 1.2.9
Keywords: view, output buffering, exception Cc: fabien
Qualification: Unreviewed

Description (Last modified by FabianLange)

Way to reproduce :

  • layout.php :
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <?php include_title() ?>
        <?php include_http_metas() ?>
        <?php include_metas() ?>
      </head>
      <body>
        avant
        <?php try { include_partial('user/widgetAccount'); } catch (Exception $e) { echo 'coucou'; }  ?>
        apres
      </body>
    </html>
    
  • components.class.php :
         function executeComponent() { throw new Exception('toto'); }
    

Result :

  • We have the expected content loaded "avant coucou apres"
  • Not any CSS nor Javascript is loaded

Why ? Because the ob_start done in sfPHPView is interrupted by an uncatched exception, and therefore is never cleaned, which leads to unexpected behavior of the sfCommonFilter who don't get a fully generated contents (well, I'm not exactly sure of the full diagnostic, but I'm sure of the cause, the consequence, and the medication).

See sfPHPView.class.php :

  • Before
        ob_start();
        ob_implicit_flush(0);
        
        require($_sfFile);
    
        return ob_get_clean();
    
  • After
        ob_start();
        ob_implicit_flush(0);
        
        try {
          require($_sfFile);
        } 
        catch (Exception $e) 
        {
          ob_end_clean();
          throw $e;
        }
    
        return ob_get_clean();
    

Uncatched exception in the middle of an output buffering, quite an unforgivable mistake ;=)

Patch included.

Attachments

patch-sfPHPView.diff (444 bytes) - added by naholyr on 11/16/09 15:07:27.
Catch exception to clean output buffering before throwing it again

Change History

11/16/09 15:07:27 changed by naholyr

  • attachment patch-sfPHPView.diff added.

Catch exception to clean output buffering before throwing it again

11/16/09 15:08:47 changed by naholyr

Forgot in the given code : "ob_end_clean()" before "throw $e" (patch is up to date).

11/16/09 15:23:44 changed by FabianLange

  • description changed.

(follow-up: ↓ 4 ) 11/16/09 15:24:10 changed by FabianLange

  • description changed.

(in reply to: ↑ 3 ) 11/16/09 21:36:08 changed by naholyr

Replying to FabianLange: Warning, you added "ob_end_clean()" in the try clause which would lead ob_get_clean() to return "" if I'm not wrong, it should only be called in the catch statement before the throw

11/16/09 21:40:53 changed by FabianLange

  • description changed.

opps was c&p issue :)

11/28/09 23:57:36 changed by FabianLange

  • status changed from new to closed.
  • resolution set to fixed.

(In [24511]) [1.2, 1.3, 1.4] correctly closing output buffering in case of exceptions while requiring a file in sfPHPView (fixes #7596)

11/28/09 23:57:59 changed by FabianLange

  • milestone set to 1.2.10.