#13961 closed defect (bug) (fixed)
search query_vars bug when using search base
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Query | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch 3.5-early |
| Cc: | bennettmcelwee, sirzooro |
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)
- 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.
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.
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 to test search instead of test%20search.
It does however work for /search/test%2520search/ it searches for test%20search as correct.
SergeyBiryukov — 2 years ago
comment:6
SergeyBiryukov — 2 years ago
- Keywords has-patch added; needs-patch removed
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)
comment:8
in reply to:
↑ 7
SergeyBiryukov — 2 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 of empty($_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.
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
comment:10
SergeyBiryukov — 2 years ago
- Keywords needs-testing added
comment:11
bennettmcelwee — 2 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.
comment:12
bennettmcelwee — 2 years ago
I have created a little plugin that effectively applies this patch.
SergeyBiryukov — 22 months ago
comment:13
in reply to:
↑ 9
SergeyBiryukov — 22 months 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.
comment:14
follow-up:
↓ 16
nacin — 19 months 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.
comment:15
nacin — 19 months ago
Also, I would think that + should be manually translated to a space for searches. That sounds like typical/proper behavior.
SergeyBiryukov — 19 months ago
comment:16
in reply to:
↑ 14
SergeyBiryukov — 19 months ago
Replying to nacin:
It should probably only apply for is_main_query() in that case.
Done in 13961.3.patch.
comment:17
azaozz — 18 months ago
- Milestone changed from 3.3 to Future Release
Not a regression or new bug.
- Milestone changed from Future Release to 3.4
Closed #19694 as a duplicate.
comment:19
sirzooro — 17 months ago
- Cc sirzooro added
comment:20
nacin — 13 months ago
- Milestone changed from 3.4 to Future Release
comment:21
nacin — 13 months ago
- Keywords 3.5-early added
comment:22
nacin — 13 months ago
Unit tests would be cool, if possible.
- Keywords needs-unit-tests added; needs-testing removed
- Milestone changed from Future Release to 3.5
Closed #21118 as a duplicate.
comment:25
markjaquith — 11 months ago
- Owner set to markjaquith
- Resolution set to fixed
- Status changed from new to closed
In [21187]:
comment:27
follow-up:
↓ 28
nacin — 11 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Should this be $this->is_main_query()? Or should we just always decode?
comment:28
in reply to:
↑ 27
;
follow-up:
↓ 29
markjaquith — 11 months 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.
comment:29
in reply to:
↑ 28
;
follow-up:
↓ 32
nacin — 11 months 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.
SergeyBiryukov — 11 months ago
Just reviewed the process again. We only want to decode values that come from /search/, not from a custom query. $this->is_main_query() indeed makes more sense.
comment:31
nacin — 11 months ago
- Resolution set to fixed
- Status changed from reopened to closed
In [21248]:

Use get_search_query() and the_search_query().