@@ -891,15 +891,15 @@ static VALUE json_parse_any(JSON_ParserState *state)
891891 return PUSH (Qnil );
892892 }
893893
894- raise_parse_error ("unexpected character: %s " , state -> cursor );
894+ raise_parse_error ("unexpected token at '%s' " , state -> cursor );
895895 break ;
896896 case 't' :
897897 if ((state -> end - state -> cursor >= 4 ) && (memcmp (state -> cursor , "true" , 4 ) == 0 )) {
898898 state -> cursor += 4 ;
899899 return PUSH (Qtrue );
900900 }
901901
902- raise_parse_error ("unexpected character: %s " , state -> cursor );
902+ raise_parse_error ("unexpected token at '%s' " , state -> cursor );
903903 break ;
904904 case 'f' :
905905 // Note: memcmp with a small power of two compile to an integer comparison
@@ -908,7 +908,7 @@ static VALUE json_parse_any(JSON_ParserState *state)
908908 return PUSH (Qfalse );
909909 }
910910
911- raise_parse_error ("unexpected character " , state -> cursor );
911+ raise_parse_error ("unexpected token at '%s' " , state -> cursor );
912912 break ;
913913 case 'N' :
914914 // Note: memcmp with a small power of two compile to an integer comparison
@@ -917,21 +917,25 @@ static VALUE json_parse_any(JSON_ParserState *state)
917917 return PUSH (CNaN );
918918 }
919919
920- raise_parse_error ("unexpected character: %s " , state -> cursor );
920+ raise_parse_error ("unexpected token at '%s' " , state -> cursor );
921921 break ;
922922 case 'I' :
923923 if (state -> config -> allow_nan && (state -> end - state -> cursor >= 8 ) && (memcmp (state -> cursor , "Infinity" , 8 ) == 0 )) {
924924 state -> cursor += 8 ;
925925 return PUSH (CInfinity );
926926 }
927927
928- raise_parse_error ("unexpected character " , state -> cursor );
928+ raise_parse_error ("unexpected token at '%s' " , state -> cursor );
929929 break ;
930930 case '-' :
931931 // Note: memcmp with a small power of two compile to an integer comparison
932- if (state -> config -> allow_nan && (state -> end - state -> cursor >= 9 ) && (memcmp (state -> cursor + 1 , "Infinity" , 8 ) == 0 )) {
933- state -> cursor += 9 ;
934- return PUSH (CMinusInfinity );
932+ if ((state -> end - state -> cursor >= 9 ) && (memcmp (state -> cursor + 1 , "Infinity" , 8 ) == 0 )) {
933+ if (state -> config -> allow_nan ) {
934+ state -> cursor += 9 ;
935+ return PUSH (CMinusInfinity );
936+ } else {
937+ raise_parse_error ("unexpected token at '%s'" , state -> cursor );
938+ }
935939 }
936940 // Fallthrough
937941 case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : {
0 commit comments