Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apollo-router/src/configuration/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,30 @@ mod test {
assert_yaml_snapshot!(value);
})
}

#[test]
fn test_dollar_escape() {
// Test that $$ is escaped to a literal $ by shellexpand
let expansion = Expansion::builder()
.mocked_env_var("API_HOST", "api.example.com")
.supported_mode("env")
.build();

let value = json!({
// $$ should become a single $
"literal_dollar": "some$$api$$key",
// $$ alongside ${env.VAR} expansion
"mixed": "https://${env.API_HOST}/path?price=$$100",
// Multiple $$ in a row
"multiple_escapes": "$$first $$second $$third",
// $$ at start and end
"edges": "$$start and end$$",
// No expansion needed (plain string)
"plain": "no dollars here"
});
let result = expansion.expand(&value).expect("expansion must succeed");
insta::with_settings!({sort_maps => true}, {
assert_yaml_snapshot!(result);
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: apollo-router/src/configuration/expansion.rs
expression: result
---
edges: $start and end$
literal_dollar: some$api$key
mixed: "https://api.example.com/path?price=$100"
multiple_escapes: $first $second $third
plain: no dollars here
7 changes: 7 additions & 0 deletions docs/source/routing/configuration/yaml.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,13 @@ headers:

Here, the `name` and `value` entries under `&insert_custom_header` are reused under `*insert_custom_header`.

### Escaping special characters

To include a literal `$` character, double it as `$$`. The router converts each `$$` to a single `$`:

- Config value: `prefix$$suffix`
- Result: `prefix$suffix`

## Related topics

- [Checklist for configuring the router for production](/technotes/TN0008-production-readiness-checklist/#apollo-router)