Skip to content

Commit

Permalink
fix(encode): Be extra sure it can be a literal
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 17, 2024
1 parent e1bc1c3 commit 3d8852b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,18 @@ fn infer_style(
}

fn infer_literal(value: &str) -> bool {
!value.contains('\'') && (value.contains('"') | value.contains('\\'))
#[cfg(feature = "parse")]
{
use winnow::stream::ContainsToken as _;
(value.contains('"') | value.contains('\\'))
&& value
.chars()
.all(|c| crate::parser::strings::LITERAL_CHAR.contains_token(c))
}
#[cfg(not(feature = "parse"))]
{
false
}
}

fn infer_all_style(value: &str) -> (StringStyle, bool) {
Expand Down

0 comments on commit 3d8852b

Please sign in to comment.