Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow non-printable characters in Strings #638

Open
vaivaswatha opened this issue Aug 21, 2019 · 0 comments
Open

Disallow non-printable characters in Strings #638

vaivaswatha opened this issue Aug 21, 2019 · 0 comments
Labels
Milestone

Comments

@vaivaswatha
Copy link
Contributor

vaivaswatha commented Aug 21, 2019

While #637 disallowed most non-printable characters, the parser and the function validate_string_literal allows a few whitespace characters.

Since there seems to be no use of allowing non-printable characters (< 32 or > 126), we can remove them (it is however a backwards incompatible change as we, today, allow few whitepspace characters to be escaped).

This involves the following changes.

  1. In ScillaLexer.mli, we have this:
and read_string buf =
  parse
  | '"'       { STRING (Buffer.contents buf) }
  | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf }
  | '\\' '/'  { Buffer.add_char buf '/'; read_string buf lexbuf }
  | '\\' 'b'  { Buffer.add_char buf '\b'; read_string buf lexbuf }
  | '\\' 'f'  { Buffer.add_char buf '\012'; read_string buf lexbuf }
  | '\\' 'n'  { Buffer.add_char buf '\n'; read_string buf lexbuf }
  | '\\' 'r'  { Buffer.add_char buf '\r'; read_string buf lexbuf }
  | '\\' 't'  { Buffer.add_char buf '\t'; read_string buf lexbuf }
  | '\\' '"'  { Buffer.add_char buf '"'; read_string buf lexbuf }
  | [^ '"' '\\']+
    { Buffer.add_string buf (Lexing.lexeme lexbuf);
      read_string buf lexbuf
    }
  | _ { raise (Error ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
  | eof { raise (Error ("String is not terminated")) }

We need to ignore all escapes except for \\ and \" (as they are both needed to allow ", a printable character, in strings).

  1. Modify validate_string_literal: remove exceptions made there for whitespaces.
  2. Update test case tests/typecheck/good/str-nonprint-char-1.scilexp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant