From afaa3b6a2066e4dacd4e7dafb5fd911bf35bdd6c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 26 Mar 2015 09:38:25 +0100 Subject: Prevent ICEs when parsing invalid escapes, closes #23620 --- src/test/parse-fail/issue-23620-invalid-escapes.rs | 45 ++++++++++++++++++++++ src/test/parse-fail/new-unicode-escapes-4.rs | 5 ++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/test/parse-fail/issue-23620-invalid-escapes.rs (limited to 'src/test/parse-fail') diff --git a/src/test/parse-fail/issue-23620-invalid-escapes.rs b/src/test/parse-fail/issue-23620-invalid-escapes.rs new file mode 100644 index 00000000000..7930ea75bf5 --- /dev/null +++ b/src/test/parse-fail/issue-23620-invalid-escapes.rs @@ -0,0 +1,45 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let _ = b"\u{a66e}"; + //~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string + + let _ = b'\u{a66e}'; + //~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string + + let _ = b'\u'; + //~^ ERROR unknown byte escape: u + + let _ = b'\x5'; + //~^ ERROR numeric character escape is too short + + let _ = b'\xxy'; + //~^ ERROR illegal character in numeric character escape: x + //~^^ ERROR illegal character in numeric character escape: y + + let _ = '\x5'; + //~^ ERROR numeric character escape is too short + + let _ = '\xxy'; + //~^ ERROR illegal character in numeric character escape: x + //~^^ ERROR illegal character in numeric character escape: y + + let _ = b"\u{a4a4} \xf \u"; + //~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string + //~^^ ERROR illegal character in numeric character escape: + //~^^^ ERROR unknown byte escape: u + + let _ = "\u{ffffff} \xf \u"; + //~^ ERROR illegal unicode character escape + //~^^ ERROR illegal character in numeric character escape: + //~^^^ ERROR form of character escape may only be used with characters in the range [\x00-\x7f] + //~^^^^ ERROR unknown character escape: u +} diff --git a/src/test/parse-fail/new-unicode-escapes-4.rs b/src/test/parse-fail/new-unicode-escapes-4.rs index ffc2b11e0c1..96b86f1f563 100644 --- a/src/test/parse-fail/new-unicode-escapes-4.rs +++ b/src/test/parse-fail/new-unicode-escapes-4.rs @@ -9,5 +9,8 @@ // except according to those terms. pub fn main() { - let s = "\u{lol}"; //~ ERROR illegal character in unicode escape + let s = "\u{lol}"; + //~^ ERROR illegal character in unicode escape: l + //~^^ ERROR illegal character in unicode escape: o + //~^^^ ERROR illegal character in unicode escape: l } -- cgit 1.4.1-3-g733a5