Skip to content

Commit

Permalink
Make strict string parsing conform to RFC 8259
Browse files Browse the repository at this point in the history
String parsing previously did not differ between strict and non-strict
modes, but was not fully compliant with RFC 8259. RFC 8259 requires that
control characters (code points < 0x20) be escaped. This is now enforced
in strict mode. In addition, non-strict mode now does *no* validations
on string contents, much like primitives in non-strict mode.
  • Loading branch information
dominickpastore committed May 26, 2020
1 parent 7ed82a3 commit a3168f0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
if (c == '\\' && parser->pos + 1 < len) {
int i;
parser->pos++;
#ifndef JSMN_STRICT
switch (js[parser->pos]) {
/* Allowed escaped symbols */
case '\"':
Expand Down Expand Up @@ -461,7 +462,16 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
parser->pos = start;
return JSMN_ERROR_INVAL;
}
#endif
}

#ifdef JSMN_STRICT
/* No control characters allowed in strict mode */
if (c >= 0 && c < 32) {
parser->pos = start;
return JSMN_ERROR_INVAL;
}
#endif
}
parser->pos = start;
return JSMN_ERROR_PART;
Expand Down

0 comments on commit a3168f0

Please sign in to comment.