aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/validation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/validation.rs')
-rw-r--r--crates/ra_syntax/src/validation.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index a550ce0ab..b560e5e85 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -5,6 +5,7 @@ use crate::{
5 ast::{self, AstNode}, 5 ast::{self, AstNode},
6 File, 6 File,
7 string_lexing::{self, CharComponentKind}, 7 string_lexing::{self, CharComponentKind},
8 utils::MutAsciiString,
8 yellow::{ 9 yellow::{
9 SyntaxError, 10 SyntaxError,
10 SyntaxErrorKind::*, 11 SyntaxErrorKind::*,
@@ -73,12 +74,18 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
73 return; 74 return;
74 } 75 }
75 76
76 let mut code = String::new(); 77 let mut buf = &mut [0; 6];
78 let mut code = MutAsciiString::new(buf);
77 let mut closed = false; 79 let mut closed = false;
78 for c in text[3..].chars() { 80 for c in text[3..].chars() {
79 assert!(!closed, "no characters after escape is closed"); 81 assert!(!closed, "no characters after escape is closed");
80 82
81 if c.is_digit(16) { 83 if c.is_digit(16) {
84 if code.len() == 6 {
85 errors.push(SyntaxError::new(OverlongUnicodeEscape, range));
86 return;
87 }
88
82 code.push(c); 89 code.push(c);
83 } else if c == '_' { 90 } else if c == '_' {
84 // Reject leading _ 91 // Reject leading _
@@ -103,10 +110,6 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
103 return; 110 return;
104 } 111 }
105 112
106 if code.len() > 6 {
107 errors.push(SyntaxError::new(OverlongUnicodeEscape, range));
108 }
109
110 match u32::from_str_radix(&code, 16) { 113 match u32::from_str_radix(&code, 16) {
111 Ok(code_u32) if code_u32 > 0x10FFFF => { 114 Ok(code_u32) if code_u32 > 0x10FFFF => {
112 errors.push(SyntaxError::new(UnicodeEscapeOutOfRange, range)); 115 errors.push(SyntaxError::new(UnicodeEscapeOutOfRange, range));