Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
63e434b4
Commit
63e434b4
authored
Nov 11, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Safe real path resolving added to `yii\console\controllers\AssetController::combineCssFiles()`
parent
112ad80d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
1 deletion
+71
-1
AssetController.php
framework/console/controllers/AssetController.php
+24
-1
AssetControllerTest.php
...nit/framework/console/controllers/AssetControllerTest.php
+47
-0
No files found.
framework/console/controllers/AssetController.php
View file @
63e434b4
...
@@ -512,9 +512,10 @@ EOD;
...
@@ -512,9 +512,10 @@ EOD;
public
function
combineCssFiles
(
$inputFiles
,
$outputFile
)
public
function
combineCssFiles
(
$inputFiles
,
$outputFile
)
{
{
$content
=
''
;
$content
=
''
;
$outputFilePath
=
dirname
(
$this
->
findRealPath
(
$outputFile
));
foreach
(
$inputFiles
as
$file
)
{
foreach
(
$inputFiles
as
$file
)
{
$content
.=
"/*** BEGIN FILE:
$file
***/
\n
"
$content
.=
"/*** BEGIN FILE:
$file
***/
\n
"
.
$this
->
adjustCssUrl
(
file_get_contents
(
$file
),
dirname
(
$
file
),
dirname
(
$outputFile
)
)
.
$this
->
adjustCssUrl
(
file_get_contents
(
$file
),
dirname
(
$
this
->
findRealPath
(
$file
)),
$outputFilePath
)
.
"/*** END FILE:
$file
***/
\n
"
;
.
"/*** END FILE:
$file
***/
\n
"
;
}
}
if
(
!
file_put_contents
(
$outputFile
,
$content
))
{
if
(
!
file_put_contents
(
$outputFile
,
$content
))
{
...
@@ -658,4 +659,26 @@ EOD;
...
@@ -658,4 +659,26 @@ EOD;
echo
"Configuration file template created at '
{
$configFile
}
'.
\n\n
"
;
echo
"Configuration file template created at '
{
$configFile
}
'.
\n\n
"
;
}
}
}
}
/**
* Returns canonicalized absolute pathname.
* Unlike regular `realpath()` this method does not expand symlinks and does not check path existence.
* @param string $path raw path
* @return string canonicalized absolute pathname
*/
private
function
findRealPath
(
$path
)
{
$path
=
str_replace
([
'/'
,
'\\'
],
DIRECTORY_SEPARATOR
,
$path
);
$pathParts
=
explode
(
DIRECTORY_SEPARATOR
,
$path
);
$realPathParts
=
[];
foreach
(
$pathParts
as
$pathPart
)
{
if
(
$pathPart
===
'..'
)
{
array_pop
(
$realPathParts
);
}
else
{
array_push
(
$realPathParts
,
$pathPart
);
}
}
return
implode
(
DIRECTORY_SEPARATOR
,
$realPathParts
);
}
}
}
tests/unit/framework/console/controllers/AssetControllerTest.php
View file @
63e434b4
...
@@ -409,4 +409,51 @@ EOL;
...
@@ -409,4 +409,51 @@ EOL;
$this
->
assertEquals
(
$expectedCssContent
,
$adjustedCssContent
,
'Unable to adjust CSS correctly!'
);
$this
->
assertEquals
(
$expectedCssContent
,
$adjustedCssContent
,
'Unable to adjust CSS correctly!'
);
}
}
/**
* Data provider for [[testFindRealPath()]]
* @return array test data
*/
public
function
findRealPathDataProvider
()
{
return
[
[
'/linux/absolute/path'
,
'/linux/absolute/path'
,
],
[
'/linux/up/../path'
,
'/linux/path'
,
],
[
'/linux/twice/up/../../path'
,
'/linux/path'
,
],
[
'/linux/../mix/up/../path'
,
'/mix/path'
,
],
[
'C:\\windows\\absolute\\path'
,
'C:\\windows\\absolute\\path'
,
],
[
'C:\\windows\\up\\..\\path'
,
'C:\\windows\\path'
,
],
];
}
/**
* @dataProvider findRealPathDataProvider
*
* @param string $sourcePath
* @param string $expectedRealPath
*/
public
function
testFindRealPath
(
$sourcePath
,
$expectedRealPath
)
{
$expectedRealPath
=
str_replace
([
'/'
,
'\\'
],
DIRECTORY_SEPARATOR
,
$expectedRealPath
);
$realPath
=
$this
->
invokeAssetControllerMethod
(
'findRealPath'
,
[
$sourcePath
]);
$this
->
assertEquals
(
$expectedRealPath
,
$realPath
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment