assistant: Normalize line endings for prompts loaded from templates (#16808)

Closes #16804

Similar to #15708, when reading prompts from a template, both Windows
and Linux might end up with `CRLF (\r\n)` line endings, which can result
in a panic.

Release Notes:

- N/A
This commit is contained in:
张小白
2024-08-26 10:34:20 -04:00
committed by GitHub
parent a28700a74d
commit 5ee4c036f9
2 changed files with 11 additions and 2 deletions
+8
View File
@@ -3041,4 +3041,12 @@ impl LineEnding {
text
}
}
pub fn normalize_cow(text: Cow<str>) -> Cow<str> {
if let Cow::Owned(replaced) = LINE_SEPARATORS_REGEX.replace_all(&text, "\n") {
replaced.into()
} else {
text
}
}
}