Skip to content
This repository

Validate UTF-8 strings. #139

Open
wants to merge 1 commit into from

1 participant

NARUSE, Yui
NARUSE, Yui
nurse commented June 10, 2012

Raise JSON::GeneratorError on converting Ruby UTF-8 string to JSON
as to JSON ASCII does.

NARUSE, Yui Validate UTF-8 strings.
Raise JSON::GeneratorError on converting Ruby UTF-8 string to JSON
as to JSON ASCII does.
da297e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 11, 2012
NARUSE, Yui Validate UTF-8 strings.
Raise JSON::GeneratorError on converting Ruby UTF-8 string to JSON
as to JSON ASCII does.
da297e9
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 1 deletion. Show diff stats Hide diff stats

  1. 13  ext/json/ext/generator/generator.c
13  ext/json/ext/generator/generator.c
@@ -273,7 +273,18 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
273 273
                     escape_len = 2;
274 274
                     break;
275 275
                 default:
276  
-                    end++;
  276
+                    {
  277
+                        unsigned short clen = trailingBytesForUTF8[c] + 1;
  278
+                        if (end + clen > len) {
  279
+                            rb_raise(rb_path2class("JSON::GeneratorError"),
  280
+                                    "partial character in source, but hit end");
  281
+                        }
  282
+                        if (!isLegalUTF8((UTF8 *) p, clen)) {
  283
+                            rb_raise(rb_path2class("JSON::GeneratorError"),
  284
+                                    "source sequence is illegal/malformed utf-8");
  285
+                        }
  286
+                        end += clen;
  287
+                    }
277 288
                     continue;
278 289
                     break;
279 290
             }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.