Repository navigation
Check listing media URLs and treat more listing fields as text - #3181
Merged
Merged
Conversation
The company video player is built from a URL saved with the listing. That URL is now checked where it is saved and where it is read, for every listing, and markup built from listing data is only printed when its media and URL attributes hold plain values. Listings by authors who can't edit job listings get embeds from WordPress's known providers only. The salary, salary currency and X / Twitter username are displayed as the text that was entered on those listings, like the company name, tagline and location already are. Brackets are encoded in a form that stays encoded when the content is processed again. Adds a test that reads the submission form's fields and checks each one on every template, so a field added later is covered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Older versions of WordPress leave it encoded when an attribute is decoded. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brackets inside HTML tags are percent-encoded: a character reference in an attribute is decoded again by the HTML filter the description passes through afterwards. Embeds in the description of a listing whose author can't edit job listings come from WordPress's known providers only, as for the company video, including embeds cached earlier. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
WordPress turns the address of a media file into a player shortcode. For a listing whose author can't edit job listings it is now a link from the start, on every path. The embed filters follow the listing whose content is being processed, which isn't always the current post. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The media URL check is now three plain conditions: cleaning the URL again doesn't change it, decoding it as HTML doesn't change it, and it has no quote, angle bracket or space. The markup check reads attribute values with WordPress's HTML parser and decodes them once more with PHP; the one remaining pattern is confined to a helper for WordPress 6.4 and 6.5. Brackets inside tags are found by letting PHP decode each character reference, so no list of the ways to write a bracket is kept. Adds tests generated from a fixed seed for the URL check and for restricted descriptions, and a test that reads the named references for brackets from PHP's own table. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes Proposed in this Pull Request
Hardening for how listing fields are displayed, following on from 2.4.9 and 2.4.10.
sanitize_meta_field_media_url()) and where it is read (get_the_company_video()), for every listing. A value that isn't a plain URL is treated as empty.protect_listing_media_output()keeps the company video player through the media pass. It now runsis_inert_media_markup()first and returns nothing if the markup fails, on every path and for every listing. This also covers markup returned by thethe_company_video_embedfilter.wpjm_esc_listing_text()andrestrict_content_html()now encode brackets as[/]through a sharedencode_brackets(). WordPress turns the unpadded[back into a bracket after it expands shortcodes, so that form did not stay encoded in content printed by a shortcode such as[job].esc_url_raw()doesn't change it a second time,html_entity_decode()doesn't change it, and it has no quote, angle bracket or space. The markup check reads attributes withWP_HTML_Tag_Processor. Brackets inside tags are found by splitting withwp_html_split()(the split WordPress itself uses for shortcodes) and letting PHP decode each character reference. One pattern for references that WordPress 6.4 and 6.5 leave undecoded is confined tohas_reference_left_before_wp_66().test_class.listing-description-processing.phpchecks the restricted description after the steps that follow the restriction.test_class.listing-field-sweep.phpreads the fields from the submission form, fills each one, and renders the listing through every listing template. A field added later is covered without a new test.test_class.listing-media-url.phpcovers the URL and markup checks.Behaviour changes to be aware of:
%5B/%5D. Link addresses keep working; a bracket in atitleoraltshows in that form.&amp;) shows no player.get_the_company_video()returns an empty string for a value that isn't a plain URL.the_job_salary()with$echo = falsereturns the brackets encoded for those listings.Testing Instructions
vendor/bin/phpunit --filter 'Tests_Listing'runs the new and changed tests..mp4URL, and another with a YouTube URL. Approve them. Both players show on the listing page, as before.[gallery]as the salary and as the X / Twitter username (enable salary under Job Listings → Settings → Job Listings). The listing page shows the text[gallery]in both places.Release Notes
New or Updated Hooks and Templates
the_company_videoandthe_company_video_embed: the filtered value is now checked before it is used. A URL that isn't a plain URL, or player markup whose media or URL attributes decode to markup, is not printed.