Description
With the Markdown Feeds experiment and its "Serve Markdown when a request prefers it via the Accept header" setting enabled, the decision only looks at the first media range of the Accept header. Quality values are not read. On a singular URL:
Accept header |
What a client means |
Served |
text/markdown;q=0.9, text/html |
prefers HTML |
Markdown |
text/markdown;q=0 |
refuses Markdown |
Markdown |
application/json, text/markdown |
accepts Markdown, not HTML |
HTML |
text/html;q=0.1, text/markdown |
prefers Markdown |
HTML |
TEXT/MARKDOWN |
Markdown |
HTML (case) |
The check is preg_match( '~^text/(?:x-)?markdown(?:[,;]|$)~', $accept ) in Markdown_Feeds::is_markdown_requested().
Expected: Markdown is served when the header prefers it over HTML, as the setting's label says, and HTML in every other case. A tie, */* or text/* should keep HTML, so browsers (text/html,...,*/*;q=0.8) and curl (*/*) are not affected.
The setting is off by default and only singular URLs negotiate, so this touches few requests today. I have a fix with tests ready and will open a PR.
Step-by-step reproduction instructions
- Enable the Markdown Feeds experiment under Settings > AI and switch on "Serve Markdown when a request prefers it via the Accept header".
- Request a published post with
curl -sI -H 'Accept: text/markdown;q=0.9, text/html' <post URL>. The response is text/markdown, although the header prefers HTML.
- Request it with
curl -sI -H 'Accept: application/json, text/markdown' <post URL>. The response is text/html, although Markdown is the only acceptable type of the two.
- Request it with
curl -sI -H 'Accept: text/markdown;q=0' <post URL>. The response is text/markdown, although the client refused it.
Screenshots, screen recording, code snippet
Output on a local site with the setting on (develop at 2cc9603):
Accept: text/markdown;q=0.9, text/html -> text/markdown
Accept: text/markdown;q=0, text/html;q=0.5 -> text/markdown
Accept: application/json, text/markdown -> text/html
Accept: text/html;q=0.1, text/markdown -> text/html
Accept: TEXT/MARKDOWN ; charset=utf-8 ; q = 1 -> text/html
Accept: text/html, text/markdown -> text/html
Accept: */* -> text/html
Environment info
- WordPress 7.1, PHP 8.5.11, SQLite (local site), pretty permalinks
- AI plugin:
develop at 2cc9603 (the Accept check is unchanged since 1.4.0)
- Theme: Twenty Twenty-Five
- No other plugins active
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.
Description
With the Markdown Feeds experiment and its "Serve Markdown when a request prefers it via the Accept header" setting enabled, the decision only looks at the first media range of the
Acceptheader. Quality values are not read. On a singular URL:Acceptheadertext/markdown;q=0.9, text/htmltext/markdown;q=0application/json, text/markdowntext/html;q=0.1, text/markdownTEXT/MARKDOWNThe check is
preg_match( '~^text/(?:x-)?markdown(?:[,;]|$)~', $accept )inMarkdown_Feeds::is_markdown_requested().Expected: Markdown is served when the header prefers it over HTML, as the setting's label says, and HTML in every other case. A tie,
*/*ortext/*should keep HTML, so browsers (text/html,...,*/*;q=0.8) andcurl(*/*) are not affected.The setting is off by default and only singular URLs negotiate, so this touches few requests today. I have a fix with tests ready and will open a PR.
Step-by-step reproduction instructions
curl -sI -H 'Accept: text/markdown;q=0.9, text/html' <post URL>. The response istext/markdown, although the header prefers HTML.curl -sI -H 'Accept: application/json, text/markdown' <post URL>. The response istext/html, although Markdown is the only acceptable type of the two.curl -sI -H 'Accept: text/markdown;q=0' <post URL>. The response istext/markdown, although the client refused it.Screenshots, screen recording, code snippet
Output on a local site with the setting on (
developat 2cc9603):Environment info
developat 2cc9603 (the Accept check is unchanged since 1.4.0)Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Please confirm which theme type you used for testing.