Skip to content

Commit 221bd2d

Browse files
committed
Simple-minded universal newline normalization
1 parent 98d1303 commit 221bd2d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/serialize_ast.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ pub(crate) fn serialize_python_file(
196196
let source_type = PySourceType::from(file_path);
197197
let source_text = match source {
198198
Some(source_text) => source_text,
199-
None => &std::fs::read_to_string(file_path)?,
199+
None => &{
200+
let content = std::fs::read_to_string(file_path)?;
201+
if !content.contains('\r') {
202+
// Fast path: nothing to normalize.
203+
content
204+
} else {
205+
content.replace("\r\n", "\n").replace("\r", "\n")
206+
}
207+
},
200208
};
201209

202210
// Compute SHA1 hash of the source text (same as mypy's compute_hash)

0 commit comments

Comments
 (0)