Skip to content

Commit 42d35a3

Browse files
authored
Merge pull request #941 from schungx/master
Fix bug in raw strings with newlines.
2 parents 1dd04cd + bcf2f14 commit 42d35a3

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Rhai Release Notes
44
Version 1.21.0
55
==============
66

7+
Bug fixes
8+
---------
9+
10+
* Fixed bug in raw strings with newlines (thanks [`@benatkin`](https://github.com/benatkin) [940](https://github.com/rhaiscript/rhai/pull/940)).
11+
712
Enhancements
813
------------
914

src/tokenizer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,10 @@ pub fn parse_raw_string_literal(
12641264

12651265
match (next_char, &mut seen_hashes) {
12661266
// New line
1267-
('\n', _) => pos.new_line(),
1267+
('\n', _) => {
1268+
result.push('\n');
1269+
pos.new_line();
1270+
}
12681271

12691272
// Begin attempt to close string
12701273
('"', None) => seen_hashes = Some(0),

tests/string.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ fn test_string() {
2020
assert_eq!(engine.eval::<String>(r##"#"Test"#"##).unwrap(), "Test");
2121
assert_eq!(engine.eval::<String>(r##"#"Test string: \\u2764\nhello,\nworld!"#"##).unwrap(), r#"Test string: \\u2764\nhello,\nworld!"#);
2222
assert_eq!(engine.eval::<String>(r###"##"Test string: #"\\u2764\nhello,\\nworld!"#"##"###).unwrap(), r##"Test string: #"\\u2764\nhello,\\nworld!"#"##);
23-
assert_eq!(engine.eval::<String>(r###"##"Test string: "## + "\u2764""###).unwrap(), "Test string: ❤");
23+
assert_eq!(
24+
engine
25+
.eval::<String>(
26+
r###"##"Test
27+
string: "## + "\u2764""###
28+
)
29+
.unwrap(),
30+
"Test\nstring: ❤"
31+
);
2432
let bad_result = *engine.eval::<String>(r###"#"Test string: \"##"###).unwrap_err();
2533
if let EvalAltResult::ErrorParsing(parse_error, pos) = bad_result {
2634
assert_eq!(parse_error, ParseErrorType::UnknownOperator("#".to_string()));

0 commit comments

Comments
 (0)