mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00: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,12 +361,12 @@ class Image extends File {
|
|||||||
foreach($methodNames as $methodName) {
|
foreach($methodNames as $methodName) {
|
||||||
if(substr($methodName, 0, 8) == 'generate') {
|
if(substr($methodName, 0, 8) == 'generate') {
|
||||||
$format = substr($methodName, 8);
|
$format = substr($methodName, 8);
|
||||||
$generateFuncs[] = $format;
|
$generateFuncs[] = preg_quote($format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// All generate functions may appear any number of times in the image cache name.
|
// All generate functions may appear any number of times in the image cache name.
|
||||||
$generateFuncs = implode('|', $generateFuncs);
|
$generateFuncs = implode('|', $generateFuncs);
|
||||||
$pattern = "/^(({$generateFuncs})\d+\-)+{$this->Name}$/i";
|
$pattern = "/^(({$generateFuncs})\d+\-)+" . preg_quote($this->Name) . "$/i";
|
||||||
|
|
||||||
foreach($cachedFiles as $cfile) {
|
foreach($cachedFiles as $cfile) {
|
||||||
if(preg_match($pattern, $cfile)) {
|
if(preg_match($pattern, $cfile)) {
|
||||||
|
@ -93,4 +93,13 @@ class ImageTest extends SapphireTest {
|
|||||||
$actual = $imageSecond->getHeight();
|
$actual = $imageSecond->getHeight();
|
||||||
$this->assertEquals($expected, $actual);
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,3 +12,7 @@ Image:
|
|||||||
imageWithoutTitleContainingDots:
|
imageWithoutTitleContainingDots:
|
||||||
Filename: assets/ImageTest/test.image.with.dots.png
|
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…
x
Reference in New Issue
Block a user