diff options
author | Florian Frank <flori@ping.de> | 2012-04-27 19:49:20 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2012-04-27 20:24:12 +0200 |
commit | 7f64f211d36e598a3c54a19d9caad9e3f9dca402 (patch) | |
tree | 90893175a786ff0cf90b63aba05ab6cc11b2387b /ext | |
parent | 7c6e8cd98fb7d841f08e083040b8316f7c752157 (diff) | |
download | json-7f64f211d36e598a3c54a19d9caad9e3f9dca402.tar.gz |
Throw exception unless source is a string
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/ext/parser/parser.c | 35 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.rl | 1 |
2 files changed, 19 insertions, 17 deletions
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index d4adb8e..c140fdb 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1721,6 +1721,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) source = convert_encoding(StringValue(source)); } json->current_nesting = 0; + StringValue(source); json->len = RSTRING_LEN(source); json->source = RSTRING_PTR(source);; json->Vsource = source; @@ -1728,7 +1729,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1732 "parser.c" +#line 1733 "parser.c" static const int JSON_start = 1; static const int JSON_first_final = 10; static const int JSON_error = 0; @@ -1736,7 +1737,7 @@ static const int JSON_error = 0; static const int JSON_en_main = 1; -#line 739 "parser.rl" +#line 740 "parser.rl" static VALUE cParser_parse_strict(VALUE self) @@ -1747,16 +1748,16 @@ static VALUE cParser_parse_strict(VALUE self) GET_PARSER; -#line 1751 "parser.c" +#line 1752 "parser.c" { cs = JSON_start; } -#line 749 "parser.rl" +#line 750 "parser.rl" p = json->source; pe = p + json->len; -#line 1760 "parser.c" +#line 1761 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1812,7 +1813,7 @@ case 5: goto st1; goto st5; tr3: -#line 728 "parser.rl" +#line 729 "parser.rl" { char *np; json->current_nesting = 1; @@ -1821,7 +1822,7 @@ tr3: } goto st10; tr4: -#line 721 "parser.rl" +#line 722 "parser.rl" { char *np; json->current_nesting = 1; @@ -1833,7 +1834,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1837 "parser.c" +#line 1838 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1890,7 +1891,7 @@ case 9: _out: {} } -#line 752 "parser.rl" +#line 753 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; @@ -1902,7 +1903,7 @@ case 9: -#line 1906 "parser.c" +#line 1907 "parser.c" static const int JSON_quirks_mode_start = 1; static const int JSON_quirks_mode_first_final = 10; static const int JSON_quirks_mode_error = 0; @@ -1910,7 +1911,7 @@ static const int JSON_quirks_mode_error = 0; static const int JSON_quirks_mode_en_main = 1; -#line 777 "parser.rl" +#line 778 "parser.rl" static VALUE cParser_parse_quirks_mode(VALUE self) @@ -1921,16 +1922,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self) GET_PARSER; -#line 1925 "parser.c" +#line 1926 "parser.c" { cs = JSON_quirks_mode_start; } -#line 787 "parser.rl" +#line 788 "parser.rl" p = json->source; pe = p + json->len; -#line 1934 "parser.c" +#line 1935 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1964,7 +1965,7 @@ st0: cs = 0; goto _out; tr2: -#line 769 "parser.rl" +#line 770 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1974,7 +1975,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1978 "parser.c" +#line 1979 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -2063,7 +2064,7 @@ case 9: _out: {} } -#line 790 "parser.rl" +#line 791 "parser.rl" if (cs >= JSON_quirks_mode_first_final && p == pe) { return result; diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index c96b0a8..20ecc48 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -705,6 +705,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) source = convert_encoding(StringValue(source)); } json->current_nesting = 0; + StringValue(source); json->len = RSTRING_LEN(source); json->source = RSTRING_PTR(source);; json->Vsource = source; |