@@ -686,11 +686,23 @@ public static function setBasePath($serverBasePath)
686686 */
687687 public static function getCurrentUri (): string
688688 {
689- // Get the current Request URI and remove rewrite base path from it (= allows one to run the router in a sub folder)
690- $ uri = substr (rawurldecode ($ _SERVER ['REQUEST_URI ' ]), strlen (static ::getBasePath ()));
689+ $ basePath = static ::getBasePath ();
690+ $ requestUri = rawurldecode ($ _SERVER ['REQUEST_URI ' ]);
691+
692+ // Early exit If base path doesn't match
693+ if (strncmp ($ requestUri , $ basePath , strlen ($ basePath )) !== 0 ) {
694+ if (!static ::$ notFoundHandler ) {
695+ static ::$ notFoundHandler = function () {
696+ \Leaf \Exception \General::default404 ();
697+ };
698+ }
699+ static ::invoke (static ::$ notFoundHandler );
700+ }
691701
692- if (strstr ($ uri , '? ' )) {
693- $ uri = substr ($ uri , 0 , strpos ($ uri , '? ' ));
702+ // Get the current Request URI and remove rewrite base path from it (= allows one to run the router in a sub folder)
703+ $ uri = substr ($ requestUri , strlen ($ basePath )) ?: '/ ' ;
704+ if (($ queryPos = strpos ($ uri , '? ' )) !== false ) {
705+ $ uri = substr ($ uri , 0 , $ queryPos );
694706 }
695707
696708 return '/ ' . trim ($ uri , '/ ' );
0 commit comments