Skip to content

Commit

Permalink
Use escape on the body in @httpRequestTest protocol test generati…
Browse files Browse the repository at this point in the history
…on (#1949)
  • Loading branch information
hlbarber authored Nov 15, 2022
1 parent a438b7c commit b2528a1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,11 @@ class ServerProtocolTestGenerator(
// corresponding Unicode code point. That is the "form feed" 0x0c character. When printing it,
// it gets written as "\f", which is an invalid Rust escape sequence: https://static.rust-lang.org/doc/master/reference.html#literals
// So we need to write the corresponding Rust Unicode escape sequence to make the program compile.
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(${
body.replace("\u000c", "\\u{000c}").dq()
}.as_bytes()))"
//
// We also escape to avoid interactions with templating in the case where the body contains `#`.
val sanitizedBody = escape(body.replace("\u000c", "\\u{000c}")).dq()
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static($sanitizedBody.as_bytes()))"
} else {
"#{SmithyHttpServer}::body::Body::empty()"
}
Expand Down

0 comments on commit b2528a1

Please sign in to comment.