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
c4595b8b
Commit
c4595b8b
authored
May 23, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #337: support strict parsing for URL manager.
parent
79598ca8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
UrlManager.php
framework/yii/web/UrlManager.php
+10
-0
UrlManagerTest.php
tests/unit/framework/web/UrlManagerTest.php
+22
-0
No files found.
framework/yii/web/UrlManager.php
View file @
c4595b8b
...
...
@@ -27,6 +27,12 @@ class UrlManager extends Component
*/
public
$enablePrettyUrl
=
false
;
/**
* @var boolean whether to enable strict parsing. If strict parsing is enabled, the incoming
* requested URL must match at least one of the [[rules]] in order to be treated as a valid request.
* This property is used only when [[enablePrettyUrl]] is true.
*/
public
$enableStrictParsing
=
false
;
/**
* @var array the rules for creating and parsing URLs when [[enablePrettyUrl]] is true.
* This property is used only if [[enablePrettyUrl]] is true. Each element in the array
* is the configuration array for creating a single URL rule. The configuration will
...
...
@@ -139,6 +145,10 @@ class UrlManager extends Component
}
}
if
(
$this
->
enableStrictParsing
)
{
return
false
;
}
$suffix
=
(
string
)
$this
->
suffix
;
if
(
$suffix
!==
''
&&
$suffix
!==
'/'
&&
$pathInfo
!==
''
)
{
$n
=
strlen
(
$this
->
suffix
);
...
...
tests/unit/framework/web/UrlManagerTest.php
View file @
c4595b8b
...
...
@@ -224,5 +224,27 @@ class UrlManagerTest extends \yiiunit\TestCase
$request
->
pathInfo
=
'site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertFalse
(
$result
);
// strict parsing
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
'enableStrictParsing'
=>
true
,
'suffix'
=>
'.html'
,
'cache'
=>
null
,
'rules'
=>
array
(
array
(
'pattern'
=>
'post/<id>/<title>'
,
'route'
=>
'post/view'
,
),
),
));
// matching pathinfo
$request
->
pathInfo
=
'post/123/this+is+sample.html'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'post/view'
,
array
(
'id'
=>
'123'
,
'title'
=>
'this+is+sample'
)),
$result
);
// unmatching pathinfo
$request
->
pathInfo
=
'site/index.html'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertFalse
(
$result
);
}
}
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