Repository navigation
fix: preserve backslashes in Fn::Sub replacement values - #9397
Merged
Merged
Conversation
reedham-aws
approved these changes
Nov 4, 2026
valerena
approved these changes
Nov 5, 2026
valerena
left a comment
Contributor
There was a problem hiding this comment.
It's always scary to change code that was last updated 7 years ago, but I don't see a reason to keep using a regex sub instead of a regular string replace, so it looks good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does this change fix?
Fixes #9396.
Why is this change necessary?
Fn::Subtreats resolved values as regex replacement strings. Backslashes can raisere.erroror silently change the value. During permissive local template resolution, an exception leaves the affected environment variable as an unresolved expression.How does it address the issue?
Use literal string replacement after resolving each substitution. Add six regressions covering parameter defaults containing unknown escapes, backreferences, newline escapes and doubled backslashes; a variable-map value; and a function environment variable resolved through the real
SamBaseProvider.What side effects does this change have?
Backslashes in resolved substitution values are preserved literally. No CLI options, dependencies or deployment APIs change.
Validation
make pron Linux/Python 3.11: 9,758 tests passed, 28 skipped, 40 subtests passed, 94.09% coverage. Schema generation, Black, Ruff and mypy passed.Mandatory Checklist
make prpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.