@@ -204,10 +204,12 @@ public function init(): void
204204 $ this ->set ('flight.case_sensitive ' , false );
205205 $ this ->set ('flight.handle_errors ' , true );
206206 $ this ->set ('flight.log_errors ' , false );
207+ $ this ->set ('flight.debug ' , false );
207208 $ this ->set ('flight.views.path ' , './views ' );
208209 $ this ->set ('flight.views.extension ' , '.php ' );
209210 $ this ->set ('flight.content_length ' , true );
210211 $ this ->set ('flight.v2.output_buffering ' , false );
212+ $ this ->set ('flight.allow_method_override ' , true );
211213
212214 // Startup configuration
213215 $ this ->before ('start ' , function () use ($ self ) {
@@ -225,6 +227,8 @@ public function init(): void
225227 // which causes a lot of problems. This will be removed
226228 // in v4
227229 $ self ->response ()->v2_output_buffering = $ this ->get ('flight.v2.output_buffering ' );
230+ // Propagate method override setting to Request
231+ $ self ->request ()::$ allowMethodOverride = (bool ) $ self ->get ('flight.allow_method_override ' );
228232 });
229233
230234 $ this ->initialized = true ;
@@ -678,16 +682,24 @@ public function _start(): void
678682 public function _error (Throwable $ e ): void
679683 {
680684 $ this ->triggerEvent ('flight.error ' , $ e );
681- $ msg = sprintf (
682- <<<'HTML'
683- <h1>500 Internal Server Error</h1>
684- <h3>%s (%s)</h3>
685- <pre>%s</pre>
686- HTML, // phpcs:ignore
687- $ e ->getMessage (),
688- $ e ->getCode (),
689- $ e ->getTraceAsString ()
690- );
685+
686+ if ($ this ->get ('flight.debug ' ) === true ) {
687+ $ msg = sprintf (
688+ <<<'HTML'
689+ <h1>500 Internal Server Error</h1>
690+ <h3>%s (%s)</h3>
691+ <pre>%s</pre>
692+ HTML, // phpcs:ignore
693+ htmlspecialchars ($ e ->getMessage (), ENT_QUOTES , 'UTF-8 ' ),
694+ $ e ->getCode (),
695+ htmlspecialchars ($ e ->getTraceAsString (), ENT_QUOTES , 'UTF-8 ' )
696+ );
697+ } else {
698+ if ($ this ->get ('flight.log_errors ' ) === true ) {
699+ error_log ($ e ->getMessage () . "\n" . $ e ->getTraceAsString ());
700+ }
701+ $ msg = '<h1>500 Internal Server Error</h1> ' ;
702+ }
691703
692704 try {
693705 $ this ->response ()
@@ -890,7 +902,7 @@ public function _redirect(string $url, int $code = 303): void
890902 }
891903
892904 // Append base url to redirect url
893- if ($ base !== '/ ' && strpos ($ url , ':// ' ) === false ) {
905+ if ($ base !== '/ ' && strpos ($ url , ':// ' ) === false ) {
894906 $ url = $ base . preg_replace ('#/+# ' , '/ ' , '/ ' . $ url );
895907 }
896908
@@ -1001,7 +1013,11 @@ public function _jsonp(
10011013 int $ option = 0
10021014 ): void {
10031015 $ json = $ encode ? Json::encode ($ data , $ option ) : $ data ;
1004- $ callback = $ this ->request ()->query [$ param ];
1016+ $ callback = (string ) $ this ->request ()->query [$ param ];
1017+
1018+ if ($ callback !== '' && !preg_match ('/^[A-Za-z_$][\w$.]{0,127}$/ ' , $ callback )) {
1019+ throw new Exception ('Invalid JSONP callback name. ' );
1020+ }
10051021
10061022 $ this ->response ()
10071023 ->status ($ code )
0 commit comments