Merge pull request #3194 from bshelton229/literal-dollar-character
Make literal $ character work in set $location_path
This commit is contained in:
commit
f56ab42cd2
3 changed files with 48 additions and 1 deletions
|
@ -120,6 +120,7 @@ var (
|
|||
}
|
||||
return true
|
||||
},
|
||||
"escapeLiteralDollar": escapeLiteralDollar,
|
||||
"shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF,
|
||||
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
|
||||
"buildLocation": buildLocation,
|
||||
|
@ -161,6 +162,20 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// escapeLiteralDollar will replace the $ character with ${literal_dollar}
|
||||
// which is made to work via the following configuration in the http section of
|
||||
// the template:
|
||||
// geo $literal_dollar {
|
||||
// default "$";
|
||||
// }
|
||||
func escapeLiteralDollar(input interface{}) string {
|
||||
inputStr, ok := input.(string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return strings.Replace(inputStr, `$`, `${literal_dollar}`, -1)
|
||||
}
|
||||
|
||||
// formatIP will wrap IPv6 addresses in [] and return IPv4 addresses
|
||||
// without modification. If the input cannot be parsed as an IP address
|
||||
// it is returned without modification.
|
||||
|
|
|
@ -858,3 +858,29 @@ func TestBuildUpstreamName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscapeLiteralDollar(t *testing.T) {
|
||||
escapedPath := escapeLiteralDollar("/$")
|
||||
expected := "/${literal_dollar}"
|
||||
if escapedPath != expected {
|
||||
t.Errorf("Expected %v but returned %v", expected, escapedPath)
|
||||
}
|
||||
|
||||
escapedPath = escapeLiteralDollar("/hello-$/world-$/")
|
||||
expected = "/hello-${literal_dollar}/world-${literal_dollar}/"
|
||||
if escapedPath != expected {
|
||||
t.Errorf("Expected %v but returned %v", expected, escapedPath)
|
||||
}
|
||||
|
||||
leaveUnchagned := "/leave-me/unchagned"
|
||||
escapedPath = escapeLiteralDollar(leaveUnchagned)
|
||||
if escapedPath != leaveUnchagned {
|
||||
t.Errorf("Expected %v but returned %v", leaveUnchagned, escapedPath)
|
||||
}
|
||||
|
||||
escapedPath = escapeLiteralDollar(false)
|
||||
expected = ""
|
||||
if escapedPath != expected {
|
||||
t.Errorf("Expected %v but returned %v", expected, escapedPath)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -347,6 +347,12 @@ http {
|
|||
}
|
||||
{{ end }}
|
||||
|
||||
# Create a variable that contains the literal $ character.
|
||||
# This works because the geo module will not resolve variables.
|
||||
geo $literal_dollar {
|
||||
default "$";
|
||||
}
|
||||
|
||||
server_name_in_redirect off;
|
||||
port_in_redirect off;
|
||||
|
||||
|
@ -913,7 +919,7 @@ stream {
|
|||
set $ingress_name "{{ $ing.Rule }}";
|
||||
set $service_name "{{ $ing.Service }}";
|
||||
set $service_port "{{ $location.Port }}";
|
||||
set $location_path "{{ $location.Path }}";
|
||||
set $location_path "{{ $location.Path | escapeLiteralDollar }}";
|
||||
|
||||
{{ if $all.Cfg.EnableOpentracing }}
|
||||
opentracing_propagate_context;
|
||||
|
|
Loading…
Reference in a new issue