Skip to content

Commit e10f09e

Browse files
committed
fix(formatter): escape double quotes when printing formatter IR
1 parent bc30892 commit e10f09e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

crates/biome_formatter/src/format_element/document.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,23 @@ impl Format<IrFormatContext> for &[FormatElement] {
250250
FormatElement::Space | FormatElement::HardSpace => {
251251
write!(f, [text(" ")])?;
252252
}
253-
element if element.is_text() => f.write_element(element.clone())?,
253+
element if element.is_text() => {
254+
// escape quotes
255+
let new_element = match element {
256+
// except for static text because source_position is unknown
257+
FormatElement::StaticText { .. } => element.clone(),
258+
FormatElement::DynamicText { text, source_position } => {
259+
let text = text.to_string().replace("\"", "\\\"");
260+
FormatElement::DynamicText { text: text.into(), source_position: *source_position }
261+
},
262+
FormatElement::LocatedTokenText { slice, source_position } => {
263+
let text = slice.to_string().replace("\"", "\\\"");
264+
FormatElement::DynamicText { text: text.into(), source_position: *source_position }
265+
},
266+
_ => unreachable!(),
267+
};
268+
f.write_element(new_element)?;
269+
},
254270
_ => unreachable!(),
255271
}
256272

0 commit comments

Comments
 (0)