Skip to content

syntax: Fix complexity of string parsing. Closes #16624. #16659

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

Merged
merged 3 commits into from
Aug 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,21 @@ pub fn str_lit(lit: &str) -> String {
loop {
match chars.next() {
Some((i, c)) => {
let em = error(i);
match c {
'\\' => {
if chars.peek().expect(em.as_slice()).val1() == '\n' {
let ch = chars.peek().unwrap_or_else(|| {
fail!("{}", error(i).as_slice())
}).val1();

if ch == '\n' {
eat(&mut chars);
} else if chars.peek().expect(em.as_slice()).val1() == '\r' {
} else if ch == '\r' {
chars.next();
if chars.peek().expect(em.as_slice()).val1() != '\n' {
let ch = chars.peek().unwrap_or_else(|| {
fail!("{}", error(i).as_slice())
}).val1();

if ch != '\n' {
fail!("lexer accepted bare CR");
}
eat(&mut chars);
Expand All @@ -433,7 +440,11 @@ pub fn str_lit(lit: &str) -> String {
}
},
'\r' => {
if chars.peek().expect(em.as_slice()).val1() != '\n' {
let ch = chars.peek().unwrap_or_else(|| {
fail!("{}", error(i).as_slice())
}).val1();

if ch != '\n' {
fail!("lexer accepted bare CR");
}
chars.next();
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-pass/slowparse-bstring.rs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/test/run-pass/slowparse-string.rs

Large diffs are not rendered by default.