25080

Symfony2 Remove UTF-8 BOM from controller responses

Question:

While creating a "force download" action I discovered that ALL responses generated by the controller are including the UTF-8 BOM (). This is not relevant for regular pages, but for downloaded files is undesirable, since JPG or ZIP are reported as corrupt for several Windows viewing softwares. So, the main goal is to remove the BOM from controller output.

Until now I've done this:

1-Use Win Grep to search for BOM chunk on every file on my site. Zero results.

2-Create a non-symfony test.php on the same web server and check output on the client. No BOM there.

Any ideas?

Thanks in advance, Z

UPDATE: Test Code 1. The resulting JPG includes the BOM.

public function downloadAction(Request $request){ $filename= 'test.jpg'; $response = new Response(file_get_contents($filename)); $response->headers->set('Content-Type',mime_content_type($filename)); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '"'); return $response;

}

Test Code 2. The resulting page also includes the BOM.

public function downloadAction(Request $request){ echo 'hello world.'; exit;

}

UPDATE2: I just tried this: create a brand new symfony2 project from scratch, added a test controller/action using same IDE, and guess what: NO BOM..so, my guess is that something inside my symfony site is intercepting the response and adding the BOM chunk.

Answer1:

The famous UTF-8 BOM had been added by LocalizeRoute.php twig extension under PEAR. In my particular case it seams Symfony filters all responses through this file, adding the BOM chunk to every page been delivered. Removing the BOM from LocalizeRoute.php was enough to fix the problem. Credits to nifr for suggesting the BOM-search. Used free window's tool WinGrep to run the binary search through the whole server. Thanks a lot.

Recommend

  • Easy Way to Get Averages Based on Names in List
  • How to send params in url query_string in Symfony?
  • How do we generate stack trace in TOMCAT?
  • Implementing Oracle.Web.dll, Oracle.DataAccess.dll 64-bit failed on Windows Server 2008 with IIS 7.5
  • Doctrine2 inverse persistance not working in nested forms
  • Unicorn and Rails eat up 2x MySQL connections
  • PHPStorm Namespace support not working for Symfony2 projects
  • Add Windows Feature from C#
  • SF2 Functional tests : “Resetting the container is not allowed when a scope is active”
  • How to enable large page memory for the JVM?
  • how do i write assembly code from c#?
  • Selenium to click on a javascript button corresponding to a text
  • Is playing sound in Javascript performance heavy?
  • Google Custom Search with transparent background
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Insert into database using onclick function
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • What is Eclipse's Declaration View used for?
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Knitr HTML Loop - Some HTML output, some R output
  • Can I make an Android app that runs a web view in Chrome 39?
  • JSON with duplicate key names losing information when parsed
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • Jquery - Jquery Wysiwyg return html as a string
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Is there a mandatory requirement to switch app.yaml?
  • Comma separated Values
  • A cron job substitute?
  • json Serialization in asp
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • how does django model after text[] in postgresql [duplicate]
  • UserPrincipal.Current returns apppool on IIS