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
if format is unknown NullMimeTypeObject is returned #8085
Conversation
|
@guilleiguaran I update the PR, it fails here |
| assert_equal request.format.html?, false | ||
| assert_equal request.format.xml?, false | ||
| assert_equal request.format.json?, false | ||
| assert !request.format.html? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use assert ! in the other lines, the last one can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I test that the request.format.html? is equal to false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important that it returns a falsy value, that evaluates to false, so !request.format.foo? should suffice I believe.
|
@carlosantoniodasilva @rails reviewers, this isn't ready for merge yet, I asked for the PR to continue working with @acapilleri in the solution and try to get everything green :) |
|
@guilleiguaran any news? |
|
This is now out of date, and will need rebased. @carlosantoniodasilva @guilleiguaran now that everything is green, is this good to go once rebased? |
|
@steveklabnik in the current PR test_send_file_headers_with_bad_symbol is the only red, but it could be delete because with this PR, `this_type_is_not_registered |
|
@guilleiguaran any thought? |
|
@acapilleri hey, thanks for ping me, I will ping to @jeremy to have some extra eyes in this one before of merge it |
|
@guilleiguaran |
|
@acapilleri I think the |
|
@pixeltrix Thanks for you code review, what class name do you think could be fine? |
|
@acapilleri if request.format.nil?
# do stuff
endIdeally the |
|
@pixeltrix right, I tried it already to fix the issue associated to this PR, isn't possible create a object that acts like @acapilleri Please rebase this and update the name to |
|
@guilleiguaran done. |
|
It still doesn't merge cleanly. |
If a request has an unknown format, the methods html?, xml?, json? ...etc not raise an Exception. This patch add a class Mime::NullType, that is returned when request.format is unknown and it responds false to the methods that ends with '?' and true to 'nil?'. It refers to rails#7837, this issue is considered a improvement not a bug.
|
updated thanks. |
if format is unknown NullMimeTypeObject is returned
|
Thanks for your contribution!!! |
This PR fixes rails#13064 regression bug introduced by the rails#8085 Ideally the NullType object would act like NilClass unfortunately that appears to be hardwired into MRI, as we know nil.to_a -> []
This PR fixes rails#13064 regression bug introduced by the rails#8085 Now in _process_format when the format is a Mime::NullType nothing is written in self.content_type. In this way the method Response#assign_default_content_type_and_charset can write the the default mime_type.
This PR fixes rails#13064 regression bug introduced by the rails#8085 Now in _process_format when the format is a Mime::NullType nothing is written in self.content_type. In this way the method Response#assign_default_content_type_and_charset can write the the default mime_type.
This PR fixes rails#13064 regression bug introduced by the rails#8085 Now in _process_format when the format is a Mime::NullType nothing is written in self.content_type. In this way the method Response#assign_default_content_type_and_charset can write the the default mime_type.
This PR is the backport of rails#13141. It fixes rails#13064 regression bug introduced by the rails#8085.
TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in rails#7837 and rails#8085 (merged in cba0588), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in rails#13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in rails#13133, merged in 43962d6. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil.
TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in rails#7837 and rails#8085 (merged in cba0588), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in rails#13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in rails#13133, merged in 43962d6. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil. Conflicts: actionpack/CHANGELOG.md actionpack/lib/abstract_controller/rendering.rb actionpack/lib/action_controller/metal/rendering.rb
TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in #7837 and #8085 (merged in cba0588), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in #13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in #13133, merged in 43962d6. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil.
TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in #7837 and #8085 (merged in cba0588), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in #13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in #13133, merged in 43962d6. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil. Conflicts: actionpack/CHANGELOG.md actionpack/lib/abstract_controller/rendering.rb actionpack/lib/action_controller/metal/rendering.rb
TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in rails#7837 and rails#8085 (merged in cba0588), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in rails#13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in rails#13133, merged in 43962d6. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil. Conflicts: actionpack/CHANGELOG.md actionpack/lib/abstract_controller/rendering.rb actionpack/lib/action_controller/metal/rendering.rb
If a unknown format is passed in a request, the methods html?, xml?, json? ...etc
Nil Exception.
This patch add a class NullMimeTypeObject, that is returned when request.format is unknown
and it responds false to the methods that ends with '?'.
It refers to #7837, it's considered a improvement not a bug.