Skip to content

Commit b2528a1

Browse files
authored
Use escape on the body in @httpRequestTest protocol test generation (#1949)
1 parent a438b7c commit b2528a1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,11 @@ class ServerProtocolTestGenerator(
532532
// corresponding Unicode code point. That is the "form feed" 0x0c character. When printing it,
533533
// it gets written as "\f", which is an invalid Rust escape sequence: https://static.rust-lang.org/doc/master/reference.html#literals
534534
// So we need to write the corresponding Rust Unicode escape sequence to make the program compile.
535-
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(${
536-
body.replace("\u000c", "\\u{000c}").dq()
537-
}.as_bytes()))"
535+
//
536+
// We also escape to avoid interactions with templating in the case where the body contains `#`.
537+
val sanitizedBody = escape(body.replace("\u000c", "\\u{000c}")).dq()
538+
539+
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static($sanitizedBody.as_bytes()))"
538540
} else {
539541
"#{SmithyHttpServer}::body::Body::empty()"
540542
}

0 commit comments

Comments
 (0)