我正在使用wordpress中的搜索查询,并且我注意到在最初的查询中,术语在花括号和数字之间.就像这样:
wp_posts.post_title LIKE '{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}11{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}'这是什么?
谢谢
发布于 2018-01-16 15:30:25
这些是%符号的占位符。如果在要与自己比较的值中发送%,则在查看'%test%'时会注意到将$query->request转换为wp_posts.post_title LIKE '{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}\{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}11{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}\{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}'。
数据库端的查询将有%。我还没有研究过为什么和在哪里做的,但最近我注意到了这一点。我相信几个版本之前不是这样的,所以这可能是最近的一次更新。
编辑:我已经调查过更多了。它是在4.8.3中添加的,来自wpdb:
/**
* Adds a placeholder escape string, to escape anything that resembles a printf() placeholder.
*
* @since 4.8.3
*
* @param string $query The query to escape.
* @return string The query with the placeholder escape string inserted where necessary.
*/
public function add_placeholder_escape( $query ) {
/*
* To prevent returning anything that even vaguely resembles a placeholder,
* we clobber every % we can find.
*/
return str_replace( '%', $this->placeholder_escape(), $query );
}
/**
* Removes the placeholder escape strings from a query.
*
* @since 4.8.3
*
* @param string $query The query from which the placeholder will be removed.
* @return string The query with the placeholder removed.
*/
public function remove_placeholder_escape( $query ) {
return str_replace( $this->placeholder_escape(), '%', $query );
}相关的trac票据是#41925,引入它是为了确保SQL不包含任何可能被sprintf误解为占位符的内容,同时带来“返回”编号占位符(这些占位符从未得到官方支持,但有效)。因安全问题而被撤职)。
https://wordpress.stackexchange.com/questions/291210
复制相似问题