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

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.
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.
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.
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 added a commit that referenced this pull request Dec 10, 2012

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

Escape \u2028 and \u2029 for 1.8

@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