Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Support escaped '/'
Browse files Browse the repository at this point in the history
Copied from chyh1990#151 by
@NBonaparte.
  • Loading branch information
gmorpheme committed Sep 15, 2021
1 parent 8511aef commit 966f2a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ impl<T: Iterator<Item = char>> Scanner<T> {
'\\' if !single => {
let mut code_length = 0usize;
match self.buffer[1] {
'/' => string.push('/'),
'0' => string.push('\0'),
'a' => string.push('\x07'),
'b' => string.push('\x08'),
Expand Down
8 changes: 8 additions & 0 deletions tests/spec_test.rs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,14 @@ fn test_ex5_12_tabs_and_spaces() {
assert_next!(v, TestEvent::OnDocumentEnd);
}

#[test]
fn test_escaped_slash() {
let mut v = str_to_test_events(NS_ESC_SLASH).into_iter();
assert_next!(v, TestEvent::OnDocumentStart);
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnDocumentEnd);
}

#[test]
fn test_ex5_13_escaped_characters() {
let mut v = str_to_test_events(EX5_13).into_iter();
Expand Down
2 changes: 2 additions & 0 deletions tests/specexamples.rs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const EX5_11 : &'static str =
const EX5_12 : &'static str =
"# Tabs and spaces\nquoted: \"Quoted\t\"\nblock: |\n void main() {\n \tprintf(\"Hello, world!\\n\");\n }";
const NS_ESC_SLASH: &'static str = "\"\\/\"";

const EX5_13 : &'static str =
"\"Fun with \\\\\n\\\" \\a \\b \\e \\f \\\n\\n \\r \\t \\v \\0 \\\n\\ \\_ \\N \\L \\P \\\n\\x41 \\u0041 \\U00000041\"";
Expand Down

0 comments on commit 966f2a2

Please sign in to comment.