Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Escape \u2028 and \u2029 for 1.8 #44

Merged
merged 4 commits into from Dec 10, 2012

Conversation

Projects
None yet
3 participants
Contributor

benmanns commented Sep 25, 2011

In 1.8, the string "\u2028" is converted to "u2028", so any JSON containing "u2028" would be replaced with "\u2028", and any string literals "\u2028" would not get escaped. This patch uses octet literals if the Ruby version is less than 1.9, and Unicode literals if the Ruby version is 1.9 or greater.

If anyone doesn't like the Ruby version comparison within the code, I can remove the comparison and use the octet literal for all versions of Ruby, because 1.9 interprets "\342\200\250" the same as "\u2028".

benmanns added some commits Sep 25, 2011

@benmanns benmanns Split "should not allow literal U+2028 or U+2029" assigns and tests f…
…or ">= 1.9" and "< 1.9".
eff0146
@benmanns benmanns Use octets in string literals when translating U+2028 and U+2029 if u…
…sing a Ruby version less than 1.9.

Previously, this would translate "u2028" to "\\u2028", because the \u escape character doesn't exist in 1.8.
4122df8
@benmanns benmanns Replace Gem::Version comparison with "\u2028" == 'u2028' comparison.
This ensures that the Unicode character is properly translated without relying on Gem::Version. Thanks to @judofyr.
2b3d626
@benmanns benmanns Move U+2028 and U+2029 into constants.
This allows the Ruby compatibility check to be run once on startup rather than for every request. Thanks to @judofyr.
75b4ef8
Contributor

jamesarosen commented Aug 19, 2012

The tests are a little hard to understand unless you've read the comments on this PR. A comment there or more descriptive naming would help.

+1 otherwise.

@rkh rkh added a commit that referenced this pull request Dec 10, 2012

@rkh rkh Merge pull request #44 from benmanns/hotfix/jsonp-escape-u2028-and-u2…
…029-for-1.8

Escape \u2028 and \u2029 for 1.8
42b92b7

@rkh rkh merged commit 42b92b7 into rack:master Dec 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment