diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d08d02c..df29083f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Rojo Changelog ## Unreleased Changes +* Fixed removing trailing newlines ([#903]) * Added Never option to Confirmation ([#893]) * Added popout diff visualizer for table properties like Attributes and Tags ([#834]) * Updated Theme to use Studio colors ([#838]) @@ -59,6 +60,7 @@ [#840]: https://github.com/rojo-rbx/rojo/pull/840 [#883]: https://github.com/rojo-rbx/rojo/pull/883 [#893]: https://github.com/rojo-rbx/rojo/pull/893 +[#903]: https://github.com/rojo-rbx/rojo/pull/903 ## [7.4.1] - February 20, 2024 * Made the `name` field optional on project files ([#870]) diff --git a/crates/memofs/src/lib.rs b/crates/memofs/src/lib.rs index 6d41c853..7a348ff6 100644 --- a/crates/memofs/src/lib.rs +++ b/crates/memofs/src/lib.rs @@ -300,7 +300,7 @@ impl Vfs { let path = path.as_ref(); let contents = self.inner.lock().unwrap().read_to_string(path)?; - Ok(contents.lines().collect::>().join("\n").into()) + Ok(contents.replace("\r\n", "\n").into()) } /// Write a file to the VFS and the underlying backend. @@ -473,3 +473,23 @@ impl VfsLock<'_> { self.inner.commit_event(event) } } + +#[cfg(test)] +mod test { + use crate::{InMemoryFs, Vfs, VfsSnapshot}; + + /// https://github.com/rojo-rbx/rojo/issues/899 + #[test] + fn read_to_string_lf_normalized_keeps_trailing_newline() { + let mut imfs = InMemoryFs::new(); + imfs.load_snapshot("test", VfsSnapshot::file("bar\r\nfoo\r\n\r\n")) + .unwrap(); + + let vfs = Vfs::new(imfs); + + assert_eq!( + vfs.read_to_string_lf_normalized("test").unwrap().as_str(), + "bar\nfoo\n\n" + ); + } +}