@@ -686,16 +686,28 @@ 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 ' ]);
691691
692- if (strstr ($ uri , '? ' )) {
693- $ uri = substr ($ uri , 0 , strpos ($ uri , '? ' ));
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+ }
701+
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 , '/ ' );
697709 }
698-
710+
699711 /**
700712 * Get route info of the current route
701713 *
0 commit comments