-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve quoted parameters in mime types #48397
Conversation
Accept headers allow parameters to be passed. They can contain quotes that need to be handled differently. These quoted strings can contain commas, which are not considered as delimiters of accept headers. Additionally, all parameters before the q-parameter should be used to lookup the media-type as well. If no media-type with the parameters is found, a fallback is introduced to the media-type without any parameters to keep the same functionality as before. Fix rails#48052
I'm confused by the error I get in the CI. I cannot reproduce this locally. Failure:
TranslationHelperTest#test_raise_arg_overrides_raise_config_option [/rails/actionview/test/template/translation_helper_test.rb:134]:
--- expected
+++ actual
@@ -1 +1 @@
-"translation missing: en.translations.missing"
+"Translation missing: en.translations.missing" I do get an error locally for the following test: rails/actionview/test/actionpack/controller/render_test.rb Lines 1085 to 1089 in c622a4d
Is this intended behaviour? This worked before specifically for strings that start with |
The error is unrelated to your changes, you can rebase your branch with the main branch and it will disappear. |
FYI there are real test failures from this change: https://buildkite.com/rails/rails/builds/96949#01888c7e-e00d-439f-8363-fe831c318682/1059-1133
The failure is due to |
This test was failing because the parameter `a` in the accept header is now being correctly extracted as a mime type. This test was expecting that Rails would extract it an an empty accept header, that will only happen now if the `q` parameter that has special meaning in used.
Sorry, that I've missed this. Thank you, @rafaelfranca, for fixing it! |
Fixes MIME parsing raising errors on valid parameters rails#51594. Mime type lookups were updated to handle custom registered types as part of rails#48397. This fix the strips out custom media range parameters before falling back to the default type creation.
Fixes MIME parsing raising errors on valid parameters rails#51594. Mime type lookups were updated to handle custom registered types as part of rails#48397. This fix the strips out custom media range parameters before falling back to the default type creation.
Fixes MIME parsing raising errors on valid parameters rails#51594. Mime type lookups were updated to handle custom registered types as part of rails#48397. This fix the strips out custom media range parameters before falling back to the default type creation.
Motivation / Background
This Pull Request has been created because
Mime::Type
does not correctly handle quoted parameters. They can contain most characters, including a comma. Additionally, the current implementation ignored the parameters when loading the type, but not when registering it.Fixes #48052
Detail
This Pull Request changes
Mime::Type
to allow every character in a quoted parameter value, except\r
,\
and"
as defined in RFC 822 3.3, except for escaped characters (see Current Limitations).Additionally, the different parts of the Accept header are not simply split by
,
, but now factor in quotes.In the current implementation
Mime::Type.register
kept the parameters, whereasMime::Type.parse
removed them. This PR now keeps all parameters before theq
parameter (as defined in RFC 7231 5.3.2). If during the lookup no type with the parameter could be found, a type is searched for without parameters as a fallback. This is useful for example formultipart/form-data; boundary="simple boundary"
and keeps the current behaviour.Current Limitations
Currently the following limitations exist, but I'm not sure if they are worth the effort:
\"
. My implementation does not allow a backslash to simplify the parsing and keeping it efficient.my/type;test="value"
would not matchmy/type; test="value"
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]