Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a comment directly after a string, byte string, or char literal being read as code when checking for a newtype or tuple inside untagged enums or unwrapped newtype variants, which rejected valid input or changed how it was deserialised ([#644](https://github.com/ron-rs/ron/pull/644))
- Fixed `Value` preallocating its sequence or map from an uncapped size hint when deserialised from a non-RON format, e.g. CBOR, so that a forged length aborted the process ([#647](https://github.com/ron-rs/ron/pull/647))
- Fixed untyped ranges, e.g. `Value` or untagged enums, rejecting an `inf` or `NaN` end bound after `..` (as in `0.0..inf` and `..NaN`) or a byte literal end bound after a bare `..` (as in `..b'z'`), which broke round-tripping compact ranges with an infinite end bound ([#648](https://github.com/ron-rs/ron/pull/648))
- Fixed `path_meta` doc comments always ending with `\n` instead of `PrettyConfig::new_line`, which mixed line endings when using e.g. `"\r\n"` ([#649](https://github.com/ron-rs/ron/pull/649))

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ impl<'a, W: fmt::Write> ser::SerializeStruct for Compound<'a, W> {
for doc_line in field.doc().lines() {
self.ser.output.write_str("/// ")?;
self.ser.output.write_str(doc_line)?;
self.ser.output.write_char('\n')?;
self.ser.output.write_str(&config.new_line)?;
indent(&mut self.ser.output, config, pretty)?;
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/544_path_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,37 @@ fn serialize_field() {
])"#
);
}

#[test]
fn doc_comments_use_new_line() {
#[derive(serde::Serialize)]
struct Pet {
name: &'static str,
age: u8,
}

let mut config = PrettyConfig::default().new_line("\r\n");

config
.path_meta
.get_or_insert_with(Field::empty)
.build_fields(|fields| {
fields
.field("age")
.with_doc("age of the pet\nmust be within range 0..256");
});

let s = ron::ser::to_string_pretty(
&Pet {
name: "Herbert",
age: 7,
},
config,
)
.unwrap();

assert_eq!(
s,
"(\r\n name: \"Herbert\",\r\n /// age of the pet\r\n /// must be within range 0..256\r\n age: 7,\r\n)"
);
}
Loading