Skip to content

Commit

Permalink
fix: escape deprecation strings in SDL (#791)
Browse files Browse the repository at this point in the history
Fixes #790
  • Loading branch information
obmarg authored Nov 14, 2023
1 parent b7337e7 commit 1b61e56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
certain circumstances.
- The generator now uses the same re-casing as codegen - leading to less bugs.
- The generator will now rename more QueryFragment fields that require it.
- `cynic-introspection` now escapes deprecated strings that require it in SDL.

## v3.2.2 - 2023-06-26

Expand Down
19 changes: 18 additions & 1 deletion cynic-introspection/src/schema/sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ impl Display for DeprecatedDisplay<'_> {
match self.0 {
Deprecated::No => {}
Deprecated::Yes(None) => write!(f, " @deprecated")?,
Deprecated::Yes(Some(reason)) => write!(f, " @deprecated(reason: \"{reason}\")")?,
Deprecated::Yes(Some(reason)) => {
write!(f, " @deprecated(reason: \"{}\")", escape_string(reason))?
}
}
Ok(())
}
Expand All @@ -349,3 +351,18 @@ impl Display for SpecifiedByDisplay<'_> {
pub fn indented<D>(f: &mut D) -> indenter::Indented<'_, D> {
indenter::indented(f).with_str(" ")
}

fn escape_string(src: &str) -> String {
let mut dest = String::with_capacity(src.len());

for character in src.chars() {
match character {
'"' | '\\' | '\n' | '\r' | '\t' => {
dest.extend(character.escape_default());
}
_ => dest.push(character),
}
}

dest
}

0 comments on commit 1b61e56

Please sign in to comment.