diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-30 17:12:56 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-30 17:12:56 +0000 |
commit | 286d90de2d213b467a092e702edf8b0706c7c1b2 (patch) | |
tree | 462c0d7ff8cf26f551c0137cbc4332219da0cf10 /crates/syntax/src/ast | |
parent | f408ff50130eae0eb56e7f9668e9df39f7baa6dd (diff) | |
parent | 6c2ce5515064011b2fde064ff18f178465383bce (diff) |
Merge #7500
7500: Fix ast::String::value not properly escaping in some cases r=Veykril a=Veykril
Fixes #7496
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 5e07ec7d1..044e3e5e8 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -173,7 +173,7 @@ impl ast::String { | |||
173 | buf.capacity() == 0, | 173 | buf.capacity() == 0, |
174 | ) { | 174 | ) { |
175 | (Ok(c), false) => buf.push(c), | 175 | (Ok(c), false) => buf.push(c), |
176 | (Ok(c), true) if Some(c) == text_iter.next() => (), | 176 | (Ok(c), true) if char_range.len() == 1 && Some(c) == text_iter.next() => (), |
177 | (Ok(c), true) => { | 177 | (Ok(c), true) => { |
178 | buf.reserve_exact(text.len()); | 178 | buf.reserve_exact(text.len()); |
179 | buf.push_str(&text[..char_range.start]); | 179 | buf.push_str(&text[..char_range.start]); |
@@ -659,7 +659,7 @@ impl Radix { | |||
659 | 659 | ||
660 | #[cfg(test)] | 660 | #[cfg(test)] |
661 | mod tests { | 661 | mod tests { |
662 | use crate::ast::{make, FloatNumber, IntNumber}; | 662 | use crate::ast::{self, make, FloatNumber, IntNumber}; |
663 | 663 | ||
664 | fn check_float_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) { | 664 | fn check_float_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) { |
665 | assert_eq!(FloatNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into()); | 665 | assert_eq!(FloatNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into()); |
@@ -692,4 +692,21 @@ mod tests { | |||
692 | check_int_suffix("0o11u32", "u32"); | 692 | check_int_suffix("0o11u32", "u32"); |
693 | check_int_suffix("0xffu32", "u32"); | 693 | check_int_suffix("0xffu32", "u32"); |
694 | } | 694 | } |
695 | |||
696 | fn check_string_value<'a>(lit: &str, expected: impl Into<Option<&'a str>>) { | ||
697 | assert_eq!( | ||
698 | ast::String { syntax: make::tokens::literal(&format!("\"{}\"", lit)) } | ||
699 | .value() | ||
700 | .as_deref(), | ||
701 | expected.into() | ||
702 | ); | ||
703 | } | ||
704 | |||
705 | #[test] | ||
706 | fn test_string_escape() { | ||
707 | check_string_value(r"foobar", "foobar"); | ||
708 | check_string_value(r"\foobar", None); | ||
709 | check_string_value(r"\nfoobar", "\nfoobar"); | ||
710 | check_string_value(r"C:\\Windows\\System32\\", "C:\\Windows\\System32\\"); | ||
711 | } | ||
695 | } | 712 | } |