html_escape all exception messages - pass query out-of-band if we want it formatted
This commit is contained in:
		
							parent
							
								
									6486bb95da
								
							
						
					
					
						commit
						c94f289291
					
				| @ -103,29 +103,21 @@ class Database | |||||||
| 
 | 
 | ||||||
|     public function commit(): bool |     public function commit(): bool | ||||||
|     { |     { | ||||||
|         if (!is_null($this->db)) { |         if (!is_null($this->db) && $this->transaction === true) { | ||||||
|             if ($this->transaction === true) { |  | ||||||
|             $this->transaction = false; |             $this->transaction = false; | ||||||
|             return $this->db->commit(); |             return $this->db->commit(); | ||||||
|         } else { |         } else { | ||||||
|                 throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call commit() as there is no transaction currently open."); |             throw new SCoreException("Unable to call commit() as there is no transaction currently open."); | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call commit() as there is no connection currently open."); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function rollback(): bool |     public function rollback(): bool | ||||||
|     { |     { | ||||||
|         if (!is_null($this->db)) { |         if (!is_null($this->db) && $this->transaction === true) { | ||||||
|             if ($this->transaction === true) { |  | ||||||
|             $this->transaction = false; |             $this->transaction = false; | ||||||
|             return $this->db->rollback(); |             return $this->db->rollback(); | ||||||
|         } else { |         } else { | ||||||
|                 throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call rollback() as there is no transaction currently open."); |             throw new SCoreException("Unable to call rollback() as there is no transaction currently open."); | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             throw new SCoreException("<p><b>Database Transaction Error:</b> Unable to call rollback() as there is no connection currently open."); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -213,7 +205,7 @@ class Database | |||||||
|             } |             } | ||||||
|             return $stmt; |             return $stmt; | ||||||
|         } catch (PDOException $pdoe) { |         } catch (PDOException $pdoe) { | ||||||
|             throw new SCoreException($pdoe->getMessage()."<p><b>Query:</b> ".$query); |             throw new SCoreException($pdoe->getMessage(), $query); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,6 +7,11 @@ | |||||||
|  */ |  */ | ||||||
| class SCoreException extends Exception | class SCoreException extends Exception | ||||||
| { | { | ||||||
|  |     public function __construct(string $msg, ?string $query=null) | ||||||
|  |     { | ||||||
|  |         parent::__construct($msg); | ||||||
|  |         $this->query = $query; | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -63,7 +63,7 @@ class UserClass | |||||||
|                     $min_ability = $a; |                     $min_ability = $a; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             throw new SCoreException("Unknown ability '".html_escape($ability)."'. Did the developer mean '".html_escape($min_ability)."'?"); |             throw new SCoreException("Unknown ability '$ability'. Did the developer mean '$min_ability'?"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -523,6 +523,8 @@ function _fatal_error(Exception $e): void | |||||||
|     //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
 |     //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
 | ||||||
|     //'.$h_hash.'
 |     //'.$h_hash.'
 | ||||||
|      |      | ||||||
|  |     $q = (!isset($e->query) || is_null($e->query)) ? "" : "<p><b>Query:</b> " . html_escape($e->query); | ||||||
|  | 
 | ||||||
|     header("HTTP/1.0 500 Internal Error"); |     header("HTTP/1.0 500 Internal Error"); | ||||||
|     echo ' |     echo ' | ||||||
| <html> | <html> | ||||||
| @ -531,7 +533,8 @@ function _fatal_error(Exception $e): void | |||||||
| 	</head> | 	</head> | ||||||
| 	<body> | 	<body> | ||||||
| 		<h1>Internal Error</h1> | 		<h1>Internal Error</h1> | ||||||
| 		<p><b>Message:</b> '.$message.' | 		<p><b>Message:</b> '.html_escape($message).' | ||||||
|  | 		'.$q.' | ||||||
| 		<p><b>Version:</b> '.$version.' (on '.phpversion().') | 		<p><b>Version:</b> '.$version.' (on '.phpversion().') | ||||||
| 	</body> | 	</body> | ||||||
| </html> | </html> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user