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
79274688
Commit
79274688
authored
Jan 01, 2015
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
urlManager: ensure route is trimmed by / on empty pattern
fixes #6717
parent
528389f0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
1 deletion
+45
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
UrlManager.php
framework/web/UrlManager.php
+1
-0
UrlRule.php
framework/web/UrlRule.php
+1
-1
UrlManagerTest.php
tests/unit/framework/web/UrlManagerTest.php
+42
-0
No files found.
framework/CHANGELOG.md
View file @
79274688
...
...
@@ -10,6 +10,7 @@ Yii Framework 2 Change Log
-
Bug #6632:
`yii\di\Container::get()`
did not handle config parameter correctly when it is passed as a constructor parameter (qiangxue)
-
Bug #6648: Added explicit type casting to avoid dblib issues on SQL Server 2014 (o-rey)
-
Bug #6691: Fixed console help description parsing with UTF8 characters (cebe)
-
Bug #6717: Fixed issue with UrlManager not matching a route on url creation when it was prefixed with
`/`
and pattern was empty (cebe)
-
Enh #4502: Added alias support to URL route when calling
`Url::toRoute()`
and
`Url::to()`
(qiangxue, lynicidn)
-
Enh #6247: Logger and error handler are now using slightly less memory (stepanselyuk, samdark)
-
Enh #6434: Added
`yii\behaviors\SluggableBehavior::immutable`
to support keeping the generated slug unchanged (trntv)
...
...
framework/web/UrlManager.php
View file @
79274688
...
...
@@ -199,6 +199,7 @@ class UrlManager extends Component
$rule
=
[
'route'
=>
$rule
];
if
(
preg_match
(
"/^((?:(
$verbs
),)*(
$verbs
))
\\
s+(.*)$/"
,
$key
,
$matches
))
{
$rule
[
'verb'
]
=
explode
(
','
,
$matches
[
1
]);
// rules that do not apply for GET requests should not be use to create urls
if
(
!
in_array
(
'GET'
,
$rule
[
'verb'
]))
{
$rule
[
'mode'
]
=
UrlRule
::
PARSING_ONLY
;
}
...
...
framework/web/UrlRule.php
View file @
79274688
...
...
@@ -131,6 +131,7 @@ class UrlRule extends Object implements UrlRuleInterface
}
$this
->
pattern
=
trim
(
$this
->
pattern
,
'/'
);
$this
->
route
=
trim
(
$this
->
route
,
'/'
);
if
(
$this
->
host
!==
null
)
{
$this
->
host
=
rtrim
(
$this
->
host
,
'/'
);
...
...
@@ -150,7 +151,6 @@ class UrlRule extends Object implements UrlRuleInterface
$this
->
pattern
=
'/'
.
$this
->
pattern
.
'/'
;
}
$this
->
route
=
trim
(
$this
->
route
,
'/'
);
if
(
strpos
(
$this
->
route
,
'<'
)
!==
false
&&
preg_match_all
(
'/<(\w+)>/'
,
$this
->
route
,
$matches
))
{
foreach
(
$matches
[
1
]
as
$name
)
{
$this
->
_routeParams
[
$name
]
=
"<
$name
>"
;
...
...
tests/unit/framework/web/UrlManagerTest.php
View file @
79274688
...
...
@@ -123,6 +123,48 @@ class UrlManagerTest extends TestCase
$this
->
assertEquals
(
'/test/post/index?page=1'
,
$url
);
}
/**
* https://github.com/yiisoft/yii2/issues/6717
*/
public
function
testCreateUrlWithEmptyPattern
()
{
$manager
=
new
UrlManager
([
'enablePrettyUrl'
=>
true
,
'cache'
=>
null
,
'rules'
=>
[
''
=>
'front/site/index'
,
],
'baseUrl'
=>
'/'
,
'scriptUrl'
=>
''
,
]);
$url
=
$manager
->
createUrl
([
'front/site/index'
]);
$this
->
assertEquals
(
'/'
,
$url
);
$url
=
$manager
->
createUrl
([
'/front/site/index'
]);
$this
->
assertEquals
(
'/'
,
$url
);
$url
=
$manager
->
createUrl
([
'front/site/index'
,
'page'
=>
1
]);
$this
->
assertEquals
(
'/?page=1'
,
$url
);
$url
=
$manager
->
createUrl
([
'/front/site/index'
,
'page'
=>
1
]);
$this
->
assertEquals
(
'/?page=1'
,
$url
);
$manager
=
new
UrlManager
([
'enablePrettyUrl'
=>
true
,
'cache'
=>
null
,
'rules'
=>
[
''
=>
'/front/site/index'
,
],
'baseUrl'
=>
'/'
,
'scriptUrl'
=>
''
,
]);
$url
=
$manager
->
createUrl
([
'front/site/index'
]);
$this
->
assertEquals
(
'/'
,
$url
);
$url
=
$manager
->
createUrl
([
'/front/site/index'
]);
$this
->
assertEquals
(
'/'
,
$url
);
$url
=
$manager
->
createUrl
([
'front/site/index'
,
'page'
=>
1
]);
$this
->
assertEquals
(
'/?page=1'
,
$url
);
$url
=
$manager
->
createUrl
([
'/front/site/index'
,
'page'
=>
1
]);
$this
->
assertEquals
(
'/?page=1'
,
$url
);
}
public
function
testCreateAbsoluteUrl
()
{
$manager
=
new
UrlManager
([
...
...
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