Skip to content

Commit

Permalink
fix #1163, fix #1164
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Sep 10, 2021
1 parent 26e8077 commit d839f39
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
32 changes: 11 additions & 21 deletions var/Typecho/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,10 @@ public static function splitByCount(int $count, int ...$sizes): int
* //output: 这是一段被截断的html文本
* </code>
*
* @access public
*
* @param string $string 需要修复处理的字符串
*
* @return string
* @param string|null $string 需要修复处理的字符串
* @return string|null
*/
public static function fixHtml(string $string): string
public static function fixHtml(?string $string): ?string
{
//关闭自闭合标签
$startPos = strrpos($string, "<");
Expand Down Expand Up @@ -406,14 +403,11 @@ public static function fixHtml(string $string): string
* //display: '<a href="http://test/test.php">hello</a>'
* </code>
*
* @access public
*
* @param string $html 需要处理的字符串
* @param string|null $html 需要处理的字符串
* @param string|null $allowableTags 需要忽略的html标签
*
* @return string
*/
public static function stripTags(string $html, ?string $allowableTags = null): string
public static function stripTags(?string $html, ?string $allowableTags = null): string
{
$normalizeTags = '';
$allowableAttributes = [];
Expand Down Expand Up @@ -562,14 +556,10 @@ public static function buildUrl(array $params): string
/**
* 处理XSS跨站攻击的过滤函数
*
* @param string $val 需要处理的字符串
*
* @param string|null $val 需要处理的字符串
* @return string
* @author kallahar@kallahar.com
* @link http://kallahar.com/smallprojects/php_xss_filter_function.php
* @access public
*/
public static function removeXSS($val)
public static function removeXSS(?string $val): string
{
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
// this prevents some character re-spacing such as <java\0script>
Expand Down Expand Up @@ -996,10 +986,10 @@ public static function checkSafeHost(string $host): bool
}

return filter_var(
$address,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
) !== false;
$address,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
) !== false;
}

/**
Expand Down
19 changes: 10 additions & 9 deletions var/Typecho/Db/Adapter/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ public static function isAvailable(): bool
*/
public function connect(Config $config)
{
if (
$dbLink = pg_connect("host={$config->host} port={$config->port}"
. " dbname={$config->database} user={$config->user} password={$config->password}")
) {
if ($config->charset) {
pg_query($dbLink, "SET NAMES '{$config->charset}'");
}
$dsn = "host={$config->host} port={$config->port}"
. " dbname={$config->database} user={$config->user} password={$config->password}";

if ($config->charset) {
$dsn .= " options='--client_encoding={$config->charset}'";
}

if ($dbLink = @pg_connect($dsn)) {
return $dbLink;
}

/** 数据库异常 */
throw new ConnectionException(pg_last_error($dbLink));
throw new ConnectionException("Couldn't connect to database.");
}

/**
Expand Down Expand Up @@ -118,7 +119,7 @@ public function fetchObject($resource): ?object
*/
public function fetchAll($resource): array
{
return pg_fetch_all($resource, PGSQL_ASSOC);
return pg_fetch_all($resource, PGSQL_ASSOC) ?: [];
}

/**
Expand Down

0 comments on commit d839f39

Please sign in to comment.