Skip to content

Commit

Permalink
Merge pull request #944 from benatkin/fix-extra-newlines-in-raw-strings
Browse files Browse the repository at this point in the history
fix extra newlines in raw strings
  • Loading branch information
schungx authored Dec 31, 2024
2 parents 42d35a3 + 70e1c54 commit 2ed0d0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}
Expand Down
9 changes: 9 additions & 0 deletions tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down

0 comments on commit 2ed0d0e

Please sign in to comment.