File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 99
1010namespace Nette \Http ;
1111
12+ use Nette ;
13+
1214
1315/**
1416 * Immutable representation of a URL with application base-path.
@@ -89,8 +91,12 @@ public function getPathInfo(): string
8991 protected function build (): void
9092 {
9193 parent ::build ();
92- $ this ->scriptPath = $ this ->scriptPath ?: $ this ->getPath ();
94+ $ path = $ this ->getPath ();
95+ $ this ->scriptPath = $ this ->scriptPath ?: $ path ;
9396 $ pos = strrpos ($ this ->scriptPath , '/ ' );
94- $ this ->basePath = $ pos === false ? '' : substr ($ this ->scriptPath , 0 , $ pos + 1 );
97+ if ($ pos === false || strncmp ($ this ->scriptPath , $ path , $ pos + 1 )) {
98+ throw new Nette \InvalidArgumentException ("ScriptPath ' $ this ->scriptPath ' doesn't match path ' $ path' " );
99+ }
100+ $ this ->basePath = substr ($ this ->scriptPath , 0 , $ pos + 1 );
95101 }
96102}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Nette \Http \UrlScript ;
6+ use Tester \Assert ;
7+
8+
9+ require __DIR__ . '/../bootstrap.php ' ;
10+
11+
12+ Assert::exception (function () {
13+ new UrlScript ('http://nette.org/file.php?q=search ' , '/a/ ' );
14+ }, Nette \InvalidArgumentException::class);
15+
16+
17+ Assert::exception (function () {
18+ new UrlScript ('http://nette.org/file.php?q=search ' , 'a ' );
19+ }, Nette \InvalidArgumentException::class);
20+
21+
22+ Assert::exception (function () {
23+ new UrlScript ('http://nette.org/dir/ ' , '/d/ ' );
24+ }, Nette \InvalidArgumentException::class);
25+
26+
27+ Assert::exception (function () {
28+ new UrlScript ('http://nette.org/dir/ ' , '/dir/index/ ' );
29+ }, Nette \InvalidArgumentException::class);
You can’t perform that action at this time.
0 commit comments