Skip to content
Snippets Groups Projects
Commit 1b14a060 authored by twistor's avatar twistor Committed by Chris Leppanen
Browse files

Issue #2510788 by twistor: Remove query string from path in FeedsEnclosure.

parent 8f278023
No related branches found
No related tags found
No related merge requests found
......@@ -315,7 +315,7 @@ class FeedsEnclosure extends FeedsElement {
*/
public function setAllowedExtensions($extensions) {
// Normalize whitespace so that empty extensions are not allowed.
$this->allowedExtensions = trim(preg_replace('/\s+/', ' ', $extensions));
$this->allowedExtensions = drupal_strtolower(trim(preg_replace('/\s+/', ' ', $extensions)));
}
/**
......@@ -371,7 +371,11 @@ class FeedsEnclosure extends FeedsElement {
return $this->safeFilename;
}
$filename = rawurldecode(drupal_basename($this->getValue()));
// Strip any query string or fragment from file name.
list($filename) = explode('?', $this->getValue());
list($filename) = explode('#', $filename);
$filename = rawurldecode(drupal_basename($filename));
if (module_exists('transliteration')) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
......@@ -385,7 +389,7 @@ class FeedsEnclosure extends FeedsElement {
$extension = FALSE;
}
else {
$extension = substr($filename, strrpos($filename, '.') + 1);
$extension = drupal_strtolower(substr($filename, strrpos($filename, '.') + 1));
}
if (!$extension || !in_array($extension, explode(' ', $this->allowedExtensions), TRUE)) {
......
......@@ -267,6 +267,14 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
$message = t('The file @file has an invalid extension.', array('@file' => $filename));
$this->assertTrue(db_query("SELECT 1 FROM {watchdog} WHERE message = :message", array(':message' => $message))->fetchField());
}
// Test that query string and fragments are removed.
$enclosure = new FeedsEnclosure('http://example.com/image.jpg?thing=stuff', 'text/plain');
$this->assertEqual($enclosure->getLocalValue(), 'image.jpg');
$enclosure = new FeedsEnclosure('http://example.com/image.jpg#stuff', 'text/plain');
$this->assertEqual($enclosure->getLocalValue(), 'image.jpg');
$enclosure = new FeedsEnclosure('http://example.com/image.JPG?thing=stuff#stuff', 'text/plain');
$this->assertEqual($enclosure->getLocalValue(), 'image.JPG');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment