? 953538.1.patch ? 953538.2.patch ? PATCHES.txt Index: plugins/FeedsFetcher.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsFetcher.inc,v retrieving revision 1.7.4.1 diff -u -p -r1.7.4.1 FeedsFetcher.inc --- plugins/FeedsFetcher.inc 29 Sep 2010 23:56:10 -0000 1.7.4.1 +++ plugins/FeedsFetcher.inc 26 Oct 2010 18:43:48 -0000 @@ -23,7 +23,7 @@ class FeedsFetcherResult extends FeedsRe * Extending classes MAY throw an exception if a problem occurred. */ public function getRaw() { - return $this->raw; + return $this->sanitizeRaw($this->raw); } /** @@ -54,7 +54,48 @@ class FeedsFetcherResult extends FeedsRe throw new Exception(t('Cannot write content to %dest', array('%dest' => $destination))); } } - return $this->file_path; + return $this->sanitizeFile($this->file_path); + } + + /** + * Sanitize the raw content string. Currently supported sanitizations: + * + * - Remove BOM header from UTF-8 files. + * + * @param string $raw + * The raw content string to be sanitized. + * @return + * The sanitized content as a string. + */ + public function sanitizeRaw($raw) { + if (substr($raw, 0,3) == pack('CCC',0xef,0xbb,0xbf)) { + $raw = substr($raw, 3); + } + return $raw; + } + + /** + * Sanitize the file in place. Currently supported sanitizations: + * + * - Remove BOM header from UTF-8 files. + * + * @param string $filepath + * The file path of the file to be sanitized. + * @return + * The file path of the sanitized file. + */ + public function sanitizeFile($filepath) { + $handle = fopen($filepath, 'r'); + $line = fgets($handle); + fclose($handle); + // If BOM header is present, read entire contents of file and overwrite + // the file with corrected contents. + if (substr($line, 0,3) == pack('CCC',0xef,0xbb,0xbf)) { + $contents = file_get_contents($filepath); + $contents = substr($contents, 3); + file_put_contents($filepath, $contents); + } + return $filepath; } } Index: plugins/FeedsFileFetcher.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsFileFetcher.inc,v retrieving revision 1.22.2.5 diff -u -p -r1.22.2.5 FeedsFileFetcher.inc --- plugins/FeedsFileFetcher.inc 5 Oct 2010 23:01:39 -0000 1.22.2.5 +++ plugins/FeedsFileFetcher.inc 26 Oct 2010 18:43:48 -0000 @@ -23,7 +23,7 @@ class FeedsFileFetcherResult extends Fee * Overrides parent::getRaw(); */ public function getRaw() { - return file_get_contents($this->file_path); + return $this->sanitizeRaw(file_get_contents($this->file_path)); } /** @@ -33,7 +33,7 @@ class FeedsFileFetcherResult extends Fee if (!file_exists($this->file_path)) { throw new Exception(t('File @filepath is not accessible.', array('@filepath' => $this->file_path))); } - return $this->file_path; + return $this->sanitizeFile($this->file_path); } } Index: plugins/FeedsHTTPFetcher.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsHTTPFetcher.inc,v retrieving revision 1.29.2.1 diff -u -p -r1.29.2.1 FeedsHTTPFetcher.inc --- plugins/FeedsHTTPFetcher.inc 29 Sep 2010 23:56:10 -0000 1.29.2.1 +++ plugins/FeedsHTTPFetcher.inc 26 Oct 2010 18:43:48 -0000 @@ -32,7 +32,7 @@ class FeedsHTTPFetcherResult extends Fee if (!in_array($result->code, array(200, 201, 202, 203, 204, 205, 206))) { throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->url, '!code' => $result->code))); } - return $result->data; + return $this->sanitizeRaw($result->data); } }