Repository: rhaiscript/rhai (language: rust)

Issue:
Fix bug in raw strings with newlines.



Discussion / hints:

Fix patch:
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 1e490c0ba..a93446dc7 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -1263,12 +1263,6 @@ pub fn parse_raw_string_literal(
         pos.advance();
 
         match (next_char, &mut seen_hashes) {
-            // New line
-            ('\n', _) => {
-                result.push('\n');
-                pos.new_line();
-            }
-
             // Begin attempt to close string
             ('"', None) => seen_hashes = Some(0),
             // Restart attempt to close string
@@ -1294,7 +1288,11 @@ pub fn parse_raw_string_literal(
                 result.push(c);
                 seen_hashes = None;
             }
-
+            // New line
+            ('\n', _) => {
+                result.push('\n');
+                pos.new_line();
+            }
             // Normal new character seen
             (c, None) => result.push(c),
         }


Test patch:
diff --git a/tests/string.rs b/tests/string.rs
index 29e91652f..b77c7e5de 100644
--- a/tests/string.rs
+++ b/tests/string.rs
@@ -29,6 +29,15 @@ string: "## + "\u2764""###
             .unwrap(),
         "Test\nstring: ❤"
     );
+    assert_eq!(
+        engine
+            .eval::<String>(
+                r###"##"Test"
+string: "## + "\u2764""###
+            )
+            .unwrap(),
+        "Test\"\nstring: ❤"
+    );
     let bad_result = *engine.eval::<String>(r###"#"Test string: \"##"###).unwrap_err();
     if let EvalAltResult::ErrorParsing(parse_error, pos) = bad_result {
         assert_eq!(parse_error, ParseErrorType::UnknownOperator("#".to_string()));