#13961 closed defect (bug) (fixed)
search query_vars bug when using search base
Reported by: | shidouhikari | Owned by: | markjaquith |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Query | Keywords: | has-patch 3.5-early |
Focuses: | Cc: |
Description
Use this debug code anywhere in a theme file:
global $wp_query; $search_string = $wp_query->query_vars['s']; echo "<p>$search_string</p>";
Then use a search form to do a normal search using more than a keyword, for exemple "search string", so that your testing site has posts that match it. It will result in something like http://domain.com/?s=search+string&submit=Go, debug will print "search string" and index.php will list all found posts as expected.
Now use search base version: http://domain.com/search/search+string ... debug prints "search+string" and since there's no post with "search-string", it is says there's no post matching.
I was unable to find where '+' should be but isn't replaced to ' ', and it's even more strange that only when search base is used that this bug happens.
Attachments (4)
Change History (36)
#3
@
14 years ago
- Component changed from General to Query
- Keywords 3.2-early needs-patch added; reporter-feedback removed
- Milestone changed from Awaiting Review to Future Release
The issue here is that ?s=test%20search
results in get_search_query()
returning 'test search', whilst, /search/test+search/
results in 'test+search' (as it should, as + is not the space character in this case), /search/test%20search/
results in 'test%20search' which IS wrong.
#4
@
14 years ago
This also causes problems for non-ASCII language search terms: #16093
As originally reported by Vladimir Kolesnikov, search results for Cyrillic keywords are incorrect when using pretty permalinks.
When using ?s=%D1%81%D0%BB%D0%BE%D0%B2%D0%BE, the search string is decoded by PHP. When using search/%D1%81%D0%BB%D0%BE%D0%B2%D0%BE/, we should perform urldecode() ourselves.
#5
@
14 years ago
The patch posted on 16093 does not work in some cases.
Patch is bad, It double-decodes
?s=...
search requests, For example,?s=test%2520search
decodes totest search
instead oftest%20search
.
It does however work for /search/test%2520search/
it searches for test%20search
as correct.
#7
follow-up:
↓ 8
@
14 years ago
Do we need to stripslashes it when it's coming from a Permastruct?
We probably should also use $wp_rewrite->using_permastruct
or something instead of empty($_GET)
#8
in reply to:
↑ 7
@
14 years ago
Replying to dd32:
Do we need to stripslashes it when it's coming from a Permastruct?
Looks like not. However it doesn't seem to have a difference in this case.
Replying to dd32:
We probably should also use
$wp_rewrite->using_permastruct
or something instead ofempty($_GET)
Did you mean $wp_rewrite->using_permalinks()
? Since a search request can come through $_GET
in this case too (and it does so in Twenty Ten search widget, regardless of the permalink structure), I guess empty($_GET)
is a more reliable check.
#9
follow-up:
↓ 13
@
14 years ago
I guess empty($_GET) is a more reliable check.
You're right in that case, patch needs testing for stripslashes/etc but seems good for 3.2
#11
@
14 years ago
- Cc bennettmcelwee added
A note for testers. This patch should also fix a related issue to do with spaces. The URL
http://domain.com/search/search%20string
should carry out a search for "search string", but it currently searches for "search%20string" instead and thus fails to find any results.
For some live examples, try these:
- http://wpdevel.wordpress.com/?s=open%20source
- http://wpdevel.wordpress.com/?s=open+source
- http://wpdevel.wordpress.com/search/open%20source
- http://wpdevel.wordpress.com/search/open+source
The first two work and the third fails, but oddly enough the fourth one works... except that the displayed search string still has the plus sign in it.
#13
in reply to:
↑ 9
@
13 years ago
- Keywords 3.2-early removed
- Milestone changed from Future Release to 3.3
Replying to dd32:
You're right in that case, patch needs testing for stripslashes/etc but seems good for 3.2
Tested the patch with keywords like //test%20search
and other examples from here.
Refreshed for 3.3.
#14
follow-up:
↓ 16
@
13 years ago
$_GET is a clever check but it seems like something could go wrong. It should probably only apply for is_main_query() in that case.
#15
@
13 years ago
Also, I would think that +
should be manually translated to a space for searches. That sounds like typical/proper behavior.
#16
in reply to:
↑ 14
@
13 years ago
Replying to nacin:
It should probably only apply for is_main_query() in that case.
Done in 13961.3.patch.
#25
@
12 years ago
- Owner set to markjaquith
- Resolution set to fixed
- Status changed from new to closed
In [21187]:
#27
follow-up:
↓ 28
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Should this be $this->is_main_query()? Or should we just always decode?
#28
in reply to:
↑ 27
;
follow-up:
↓ 29
@
12 years ago
Replying to nacin:
Should this be $this->is_main_query()? Or should we just always decode?
If someone is manually doing a new WP_Query, I don't think we want to decode.
#29
in reply to:
↑ 28
;
follow-up:
↓ 32
@
12 years ago
Replying to markjaquith:
Replying to nacin:
Should this be $this->is_main_query()? Or should we just always decode?
If someone is manually doing a new WP_Query, I don't think we want to decode.
Sure. But right now this will always fire on new WP_Query, unless query_posts() was used, as is_main_query() will just return true. This needs to be $this->is_main_query().
Kinda want to deprecate the is_main_query() function and leave just the method. It's confusing.
Use get_search_query() and the_search_query().