mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: regex-escape strings to prevent regex syntax errors
Apply preg_quote to each generator name and to $this->Name so that their use in a regular expression will not cause run-time errors. Provided fixture and test.
This commit is contained in:
parent
39da4bef74
commit
5f1faec3e2
@ -361,13 +361,13 @@ class Image extends File {
|
||||
foreach($methodNames as $methodName) {
|
||||
if(substr($methodName, 0, 8) == 'generate') {
|
||||
$format = substr($methodName, 8);
|
||||
$generateFuncs[] = $format;
|
||||
$generateFuncs[] = preg_quote($format);
|
||||
}
|
||||
}
|
||||
// All generate functions may appear any number of times in the image cache name.
|
||||
$generateFuncs = implode('|', $generateFuncs);
|
||||
$pattern = "/^(({$generateFuncs})\d+\-)+{$this->Name}$/i";
|
||||
|
||||
$pattern = "/^(({$generateFuncs})\d+\-)+" . preg_quote($this->Name) . "$/i";
|
||||
|
||||
foreach($cachedFiles as $cfile) {
|
||||
if(preg_match($pattern, $cfile)) {
|
||||
if(Director::fileExists($cacheDir . $cfile)) {
|
||||
|
@ -93,4 +93,13 @@ class ImageTest extends SapphireTest {
|
||||
$actual = $imageSecond->getHeight();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
function testGeneratedImageDeletion() {
|
||||
$image = $this->objFromFixture('Image', 'imageWithMetacharacters');
|
||||
$image_generated = $image->SetWidth(200);
|
||||
$p = $image_generated->getFullPath();
|
||||
$this->assertTrue(file_exists($p));
|
||||
$image->deleteFormattedImages();
|
||||
$this->assertFalse(file_exists($p));
|
||||
}
|
||||
}
|
@ -11,4 +11,8 @@ Image:
|
||||
Parent: =>Folder.folder1
|
||||
imageWithoutTitleContainingDots:
|
||||
Filename: assets/ImageTest/test.image.with.dots.png
|
||||
Parent: =>Folder.folder1
|
||||
Parent: =>Folder.folder1
|
||||
imageWithMetacharacters:
|
||||
Title: This is a/an image Title
|
||||
Filename: assets/ImageTest/test_image*).png
|
||||
Parent: =>Folder.folder1
|
||||
|
Loading…
Reference in New Issue
Block a user