Skip to content

Commit

Permalink
Fix bug in raw strings with newlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Dec 10, 2024
1 parent ae6e9d4 commit bcf2f14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Rhai Release Notes
Version 1.21.0
==============

Bug fixes
---------

* Fixed bug in raw strings with newlines (thanks [`@benatkin`](https://github.com/benatkin) [940](https://github.com/rhaiscript/rhai/pull/940)).

Enhancements
------------

Expand Down
5 changes: 4 additions & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,10 @@ pub fn parse_raw_string_literal(

match (next_char, &mut seen_hashes) {
// New line
('\n', _) => pos.new_line(),
('\n', _) => {
result.push('\n');
pos.new_line();
}

// Begin attempt to close string
('"', None) => seen_hashes = Some(0),
Expand Down
10 changes: 9 additions & 1 deletion tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ fn test_string() {
assert_eq!(engine.eval::<String>(r##"#"Test"#"##).unwrap(), "Test");
assert_eq!(engine.eval::<String>(r##"#"Test string: \\u2764\nhello,\nworld!"#"##).unwrap(), r#"Test string: \\u2764\nhello,\nworld!"#);
assert_eq!(engine.eval::<String>(r###"##"Test string: #"\\u2764\nhello,\\nworld!"#"##"###).unwrap(), r##"Test string: #"\\u2764\nhello,\\nworld!"#"##);
assert_eq!(engine.eval::<String>(r###"##"Test string: "## + "\u2764""###).unwrap(), "Test string: ❤");
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()));
Expand Down

0 comments on commit bcf2f14

Please sign in to comment.