Reader search drops everything after an & in the search phrase

Đang mở Phù hợp với người mới
#26,254 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
83/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ios, objective-c
Lĩnh vực
mobile

Hướng nghiên cứu

Đọc Modules/Sources/WordPressKitObjC/ReaderPostServiceRemote.m và ReaderPostServiceRemoteTests.m, bắt đầu với endpointUrlForSearchPhrase: và testEndpointUrlForSearchPhrase. Cập nhật bài kiểm thử để mong đợi dấu và được mã hóa trong giá trị truy vấn, rồi xác minh bằng NSURLComponents rằng q là mục truy vấn duy nhất và chứa toàn bộ cụm từ. Issue hoàn tất khi các kiểm tra đó thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

[Status] Ready for Dev [Type] Bug Reader

Reader search drops everything after an & in the search phrase. Searching for "coffee & cake" returns the same results as searching for "coffee ".

What happens

ReaderPostServiceRemote endpointUrlForSearchPhrase: puts the phrase into the URL with wp_stringByUrlEncoding. That helper encodes with URLQueryAllowedCharacterSet, which leaves & as it is. So the & ends the q parameter:

Phrase Request What the server gets
coffee & cake read/search?q=coffee%20&%20cake q = "coffee ", plus a stray parameter named " cake"
coffee read/search?q=coffee q = "coffee"

The existing test testEndpointUrlForSearchPhrase in ReaderPostServiceRemoteTests.m asserts exactly this output (hasSuffix:@"q=coffee%20&%20cake"), so it passes today.

Evidence

Checked on 2026-10-27:

  • Encoding. A probe running the same code as wp_stringByUrlEncoding produced q=coffee%20&%20cake. NSURLComponents then reads q as "coffee ", with 2 query items.

  • Server. GET /rest/v1.2/read/search?number=5&q=…:

    q sent Results
    coffee%20&%20cake (what the app sends) identical to coffee%20
    coffee%20 —
    coffee%20%26%20cake (correctly encoded) different posts
  • + is not affected in practice: c++, c%20%20 and c%2B%2B return the same results.

Checked in the app: "coffee & cake" and "coffee" return identical results. Screenshots are in the first comment.

Steps to reproduce

  1. Reader → Search.
  2. Search for coffee & cake and note the posts.
  3. Search for coffee and compare.

Expected: different results, matching posts about coffee and cake.
Actual: the same results as coffee.

Fix

Encode the phrase as a query value in endpointUrlForSearchPhrase: (Modules/Sources/WordPressKitObjC/ReaderPostServiceRemote.m). Don't change wp_stringByUrlEncoding itself, because PeopleServiceRemote uses it to encode whole avatar URLs, where & must stay as it is.

NSMutableCharacterSet *allowed = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
[allowed removeCharactersInString:@"&+=#"];
NSString *query = [phrase stringByAddingPercentEncodingWithAllowedCharacters:allowed];
NSString *endpoint = [NSString stringWithFormat:@"read/search?q=%@", query];

The endpoint string is also the search topic's path, its lookup key. Saved searches for phrases containing & will get a new topic, which is fine.

Tests

In ReaderPostServiceRemoteTests.m, testEndpointUrlForSearchPhrase:

  • Change the coffee & cake assertion to expect q=coffee%20%26%20cake.
  • Add a check that the URL's q query item, read with NSURLComponents, is exactly coffee & cake, and that it's the only query item. This fails on trunk.

Related: found while planning #6632, which adds a lang parameter to the same URL.

Ngôn ngữ chính
Swift
Star
3.9k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
136

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wordpress-mobile/WordPress-iOS

Tất cả issue của wordpress-mobile/WordPress-iOS

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.