Use esc_url_raw() for avatar URLs in AJAX responses#4903
Use esc_url_raw() for avatar URLs in AJAX responses#4903GaryJones wants to merge 2 commits intobuddyboss:releasefrom
Conversation
The avatar upload and crop AJAX handlers use esc_url() to encode the avatar URL before returning it in a JSON response. esc_url() is designed for HTML output and encodes ampersands and other characters that are valid in raw URLs, which can break the URL when JavaScript consumes it. Switch to esc_url_raw() which sanitises without encoding for display context, preserving the URL for programmatic use.
|
@claude Review the PR |
|
Claude finished @chetansatasiya's task in 1m 12s —— View job PR Review
SummaryThe fix is correct and well-reasoned. Using Changes Reviewed (
|
Problem
The avatar upload and crop AJAX handlers in
bp-core/bp-core-avatars.phpuseesc_url()to encode the avatar URL before returning it in a JSON response.esc_url()is designed for HTML output contexts — it encodes ampersands as&, strips certain characters, and performs other transformations appropriate for embedding URLs in HTML attributes. When the URL is returned in a JSON response for JavaScript consumption, these transformations corrupt the URL. Query string parameters with&become&, and certain valid URL characters may be stripped entirely.Fix
Switch both occurrences to
esc_url_raw(), which performs the same sanitisation (protocol validation, invalid character removal) without the HTML-specific encoding. This is the correct function for URLs that will be used programmatically rather than output in HTML.This follows the WordPress Codex guidance: use
esc_url()for HTML output,esc_url_raw()for database storage, redirects, and HTTP API usage.Test plan