]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
From Lua 5.2: Change \* to \z. Reject undefined escape sequences.
authorMike Pall <mike>
Tue, 19 Jul 2011 18:58:10 +0000 (20:58 +0200)
committerMike Pall <mike>
Tue, 19 Jul 2011 18:58:10 +0000 (20:58 +0200)
src/lj_lex.c

index 01e0c641a711f63142fd880575f954100be079cc..00daccd5489ba1666e2c23217754da4fb27410ee 100644 (file)
@@ -238,9 +238,8 @@ static void read_string(LexState *ls, int delim, TValue *tv)
       lj_lex_error(ls, TK_string, LJ_ERR_XSTR);
       continue;
     case '\\': {
-      int c;
-      next(ls);  /* Skip the '\\'. */
-      switch (ls->current) {
+      int c = next(ls);  /* Skip the '\\'. */
+      switch (c) {
       case 'a': c = '\a'; break;
       case 'b': c = '\b'; break;
       case 'f': c = '\f'; break;
@@ -260,31 +259,30 @@ static void read_string(LexState *ls, int delim, TValue *tv)
          c += 9;
        }
        break;
-      case '*':  /* Skip whitespace. */
+      case 'z':  /* Skip whitespace. */
        next(ls);
        while (lj_char_isspace(ls->current))
          if (currIsNewline(ls)) inclinenumber(ls); else next(ls);
        continue;
       case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
+      case '\\': case '\"': case '\'': break;
       case END_OF_STREAM: continue;
       default:
-       if (!lj_char_isdigit(ls->current)) {
-         save_and_next(ls);  /* Handles '\\', '\"' and "\'". */
-       } else {  /* Decimal escape '\ddd'. */
-         c = (ls->current - '0');
+       if (!lj_char_isdigit(c))
+         goto err_xesc;
+       c -= '0';  /* Decimal escape '\ddd'. */
+       if (lj_char_isdigit(next(ls))) {
+         c = c*10 + (ls->current - '0');
          if (lj_char_isdigit(next(ls))) {
            c = c*10 + (ls->current - '0');
-           if (lj_char_isdigit(next(ls))) {
-             c = c*10 + (ls->current - '0');
-             if (c > 255) {
-             err_xesc:
-               lj_lex_error(ls, TK_string, LJ_ERR_XESC);
-             }
-             next(ls);
+           if (c > 255) {
+           err_xesc:
+             lj_lex_error(ls, TK_string, LJ_ERR_XESC);
            }
+           next(ls);
          }
-         save(ls, c);
        }
+       save(ls, c);
        continue;
       }
       save(ls, c);