Skip to content
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

Handle JSON requests that return a single space #256

Merged
merged 1 commit into from
Aug 15, 2011

Conversation

rosshale
Copy link

In Rails, specifying "head :ok" or "render => :nothing" returns a single space instead of an empty string in the response body. This commit checks xhr.responseText against the single space case. Tests included!

…n/json' that return an empty body (as in "head :ok")
@kossnocorp
Copy link
Contributor

I think instead:

xhr.responseText == '' || xhr.responseText == ' '

...we should use:

xhr.responseText.replace(/\s/g, '') === ''

@madrobby
Copy link
Owner

How about...

/^\s*$/.test(xhr.responseText)

shorter and should be faster than a replace.

madrobby added a commit that referenced this pull request Aug 15, 2011
---

In Rails, specifying "head :ok" or "render => :nothing" returns a single space instead of an empty string in the response body.  This commit checks xhr.responseText against the single space case.  Tests included!
madrobby added a commit that referenced this pull request Aug 15, 2011
@madrobby madrobby merged commit a822d60 into madrobby:master Aug 15, 2011
@rosshale
Copy link
Author

Sweet, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants