about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-04 22:25:42 -0700
committerbors <bors@rust-lang.org>2013-09-04 22:25:42 -0700
commit2bd628eafab1225cdc59c468c32868302b5e92ed (patch)
treeb829c2bec200e439c31f1f80a42520c394783dbb /src/libstd
parentd285ea791058f7db8bef828740aae95e69becc99 (diff)
parentba1f663bbd988ad0c12aacaaa94d9e36b91dac81 (diff)
downloadrust-2bd628eafab1225cdc59c468c32868302b5e92ed.tar.gz
rust-2bd628eafab1225cdc59c468c32868302b5e92ed.zip
auto merge of #8944 : alexcrichton/rust/issue-8938, r=huonw
Otherwise extra stuff after a lone '}' character is simply ignored, which is
very bad.

Closes #8938
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fmt/parse.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs
index 4bfa6b5afce..245318c4699 100644
--- a/src/libstd/fmt/parse.rs
+++ b/src/libstd/fmt/parse.rs
@@ -149,6 +149,7 @@ pub struct SelectArm<'self> {
 pub struct Parser<'self> {
     priv input: &'self str,
     priv cur: str::CharOffsetIterator<'self>,
+    priv depth: uint,
 }
 
 impl<'self> iterator::Iterator<Piece<'self>> for Parser<'self> {
@@ -168,6 +169,11 @@ impl<'self> iterator::Iterator<Piece<'self>> for Parser<'self> {
                 self.escape(); // ensure it's a valid escape sequence
                 Some(String(self.string(pos + 1))) // skip the '\' character
             }
+            Some((_, '}')) if self.depth == 0 => {
+                self.cur.next();
+                self.err(~"unmatched `}` found");
+                None
+            }
             Some((_, '}')) | None => { None }
             Some((pos, _)) => {
                 Some(String(self.string(pos)))
@@ -182,6 +188,7 @@ impl<'self> Parser<'self> {
         Parser {
             input: s,
             cur: s.char_offset_iter(),
+            depth: 0,
         }
     }
 
@@ -393,7 +400,9 @@ impl<'self> Parser<'self> {
             if !self.wsconsume('{') {
                 self.err(~"selector must be followed by `{`");
             }
+            self.depth += 1;
             let pieces = self.collect();
+            self.depth -= 1;
             if !self.wsconsume('}') {
                 self.err(~"selector case must be terminated by `}`");
             }
@@ -494,7 +503,9 @@ impl<'self> Parser<'self> {
             if !self.wsconsume('{') {
                 self.err(~"selector must be followed by `{`");
             }
+            self.depth += 1;
             let pieces = self.collect();
+            self.depth -= 1;
             if !self.wsconsume('}') {
                 self.err(~"selector case must be terminated by `}`");
             }