-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.5] Fix expectsJson returning true when expecting html #22459
Conversation
Looking at the Would be nice if we can get a test demonstrating where the bug is if possible |
This is most probably an error in your code somewhere. Show the request headers your ajax call is generating, and at least a failing test for wantsJson. If you're right we want to fix this with a test that verifies that the fix is never forgotten/reversed. |
The current code is:
So in my code the |
You're right; I was only thinking of the Accept header. The comment even says "Determine if the current request probably expects a JSON response", my emphasis. Changing what expectsJson does in a released version would be a breaking change. I would suggest that you target the 5.6 release (the master branch) and add some tests to make sure your new functionality stays in place and aren't accidentally refactored away. |
Might be better to use |
Is there a reason you didn't use |
Thanks @sisve, I was really worried that changing this could cause problems. I'm busy now, but I should be able to work on it from the 21st, and I'll add some tests. |
@taylorotwell in my code I can use |
I've found where I can override the If someone has an idea how to fix this without a breaking change I make the change, otherwise I think it will be better to close this pull request and add a better solution in version Thank you all for your help. |
Is this really a breaking change or is it a bug fix? We are literally telling the backend we want HTML and Laravel is saying "oh this request expects JSON!"... that's a bug. |
expectsJson() says that the request probably wants json when a request has The assumption that all ajax calls expects a json response is weird. I consider this both a bug, and a huge breaking change. We have no idea how expectsJson() is used in the wild, and how many sites will break if we change it now. |
What do you think of this solution?
If the request is ajax and is not pjax and the expected Then: Do you think this solves the bug without adding a breaking change? |
Any change to expectsJson() is a breaking change. I think it should target 5.6 (the master branch) where breaking changes are allowed. |
I think you are confusing this with |
@jn-jairo It's should return JSON response ( as expected ) because, your request is ajax
here is |
@pavinthan He's telling jQuery to expect a html result, and he sends a |
That correct, small suggestion why this may change like
if someones need the JSON response, they should have Accept header |
I still think that this should target the 5.6 release (the master branch). |
Guys please review laravel/ideas#933 |
5c9d906
to
48f142f
Compare
I opened a pull request targeting I'll let you decide which branch to apply this to. |
The function
expectsJson
was returningtrue
when not expecting JSON but expecting HTML.I got this error in the return of a validation, it always returns a JSON, even when I put a
dataType: 'html'
.Example:
I hope this correction is satisfactory, I could not think of a more elegant way to solve the problem without risking breaking someone's code.