MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve strict mode validation for octal escapes and literals

+19 -7
+5
include/strings.h
··· 17 17 ); 18 18 } 19 19 20 + static inline bool is_octal_escape(const uint8_t *in, size_t pos) { 21 + uint8_t c = in[pos + 1]; 22 + return c >= '0' && c <= '7' && !(c == '0' && !(in[pos + 2] >= '0' && in[pos + 2] <= '7')); 23 + } 24 + 20 25 size_t decode_escape( 21 26 const uint8_t *in, size_t pos, size_t end, 22 27 uint8_t *out, size_t *out_pos, uint8_t quote
+14 -7
src/ant.c
··· 4454 4454 return TOK_ERR; 4455 4455 } 4456 4456 numlen = parse_legacy_octal(buf, remaining, &value); 4457 + } else if (is_digit(buf[1]) && (js->flags & F_STRICT)) { 4458 + js->tok = TOK_ERR; 4459 + js->tlen = 1; 4460 + return TOK_ERR; 4457 4461 } else numlen = parse_decimal(buf, remaining, &value); 4458 4462 } else numlen = parse_decimal(buf, remaining, &value); 4459 4463 ··· 8249 8253 8250 8254 for (size_t i = part_start; i < n; i++) { 8251 8255 if (in[i] == '\\' && i + 1 < n) { 8252 - if (in[i + 1] >= '1' && in[i + 1] <= '7') return js_mkerr_typed( 8253 - js, JS_ERR_SYNTAX, "octal escape sequences are not allowed in template literals" 8256 + if (is_octal_escape(in, i)) return js_mkerr_typed( 8257 + js, JS_ERR_SYNTAX, "Octal escape sequences are not allowed in template strings." 8254 8258 ); 8255 8259 i += 1 + decode_escape(in, i, n, out, &out_len, '`'); 8256 8260 } else out[out_len++] = in[i]; ··· 8345 8349 8346 8350 for (size_t i = part_start; i < n; i++) { 8347 8351 if (in[i] == '\\' && i + 1 < n) { 8348 - if (in[i + 1] >= '1' && in[i + 1] <= '7') return js_mkerr_typed( 8349 - js, JS_ERR_SYNTAX, "octal escape sequences are not allowed in template literals" 8352 + if (is_octal_escape(in, i)) return js_mkerr_typed( 8353 + js, JS_ERR_SYNTAX, "Octal escape sequences are not allowed in template strings." 8350 8354 ); 8351 8355 i += 1 + decode_escape(in, i, n, out, &out_len, '`'); 8352 8356 } else out[out_len++] = in[i]; ··· 8403 8407 uint8_t *out = &js->mem[js->brk + sizeof(jsoff_t)]; 8404 8408 while (n2++ + 2 < js->tlen) { 8405 8409 if (in[n2] == '\\') { 8406 - if (in[n2 + 1] >= '1' && in[n2 + 1] <= '7' && (js->flags & F_STRICT)) return js_mkerr_typed( 8407 - js, JS_ERR_SYNTAX, "octal escape sequences are not allowed in strict mode" 8410 + if ((js->flags & F_STRICT) && is_octal_escape(in, n2)) return js_mkerr_typed( 8411 + js, JS_ERR_SYNTAX, "Octal escape sequences are not allowed in strict mode." 8408 8412 ); 8409 8413 size_t extra = decode_escape(in, n2, js->tlen, out, &n1, in[0]); 8410 8414 n2 += extra + 1; ··· 9207 9211 case TOK_ERR: 9208 9212 if ((js->flags & F_STRICT) && js->toff < js->clen && js->code[js->toff] == '0' && 9209 9213 js->toff + 1 < js->clen && is_digit(js->code[js->toff + 1])) { 9210 - return js_mkerr_typed(js, JS_ERR_SYNTAX, "octal literals are not allowed in strict mode"); 9214 + uint8_t d = js->code[js->toff + 1]; 9215 + return js_mkerr_typed(js, JS_ERR_SYNTAX, d >= '0' && d <= '7' 9216 + ? "Octal literals are not allowed in strict mode." 9217 + : "Decimals with leading zeros are not allowed in strict mode."); 9211 9218 } 9212 9219 return js_mkerr_typed(js, JS_ERR_SYNTAX, "parse error"); 9213 9220 case TOK_NUMBER: return js->tval;