Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Validate UTF-8 strings. #139

Open
wants to merge 1 commit into from

1 participant

@nurse

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

@nurse nurse 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
Commits on Jun 11, 2012
  1. @nurse

    Validate UTF-8 strings.

    nurse authored
    Raise JSON::GeneratorError on converting Ruby UTF-8 string to JSON
    as to JSON ASCII does.
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 1 deletion.
  1. +12 −1 ext/json/ext/generator/generator.c
View
13 ext/json/ext/generator/generator.c
@@ -273,7 +273,18 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
escape_len = 2;
break;
default:
- end++;
+ {
+ unsigned short clen = trailingBytesForUTF8[c] + 1;
+ if (end + clen > len) {
+ rb_raise(rb_path2class("JSON::GeneratorError"),
+ "partial character in source, but hit end");
+ }
+ if (!isLegalUTF8((UTF8 *) p, clen)) {
+ rb_raise(rb_path2class("JSON::GeneratorError"),
+ "source sequence is illegal/malformed utf-8");
+ }
+ end += clen;
+ }
continue;
break;
}
Something went wrong with that request. Please try again.