From f85d072c17383c938b61d997a8604d0bad103dfc Mon Sep 17 00:00:00 2001 From: Chris Marchbanks Date: Tue, 24 Jan 2023 09:15:52 -0700 Subject: [PATCH] Datasources: Fix Proxy by UID Failing for UIDs with a Hyphen (#61723) Fix Proxy by UID Failing for UIDs with a Hyphen Hyphens are allowed in short IDs but not picked up by the proxyPathRegexp. This caused the end of the uid to be proxied as part of the path to the backing datasource which would usually cause a 404. --- pkg/services/datasourceproxy/datasourceproxy.go | 2 +- pkg/services/datasourceproxy/datasourceproxy_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/services/datasourceproxy/datasourceproxy.go b/pkg/services/datasourceproxy/datasourceproxy.go index 81a2f5fdb1c..c6346fa9682 100644 --- a/pkg/services/datasourceproxy/datasourceproxy.go +++ b/pkg/services/datasourceproxy/datasourceproxy.go @@ -132,7 +132,7 @@ func (p *DataSourceProxyService) proxyDatasourceRequest(c *models.ReqContext, ds proxy.HandleRequest() } -var proxyPathRegexp = regexp.MustCompile(`^\/api\/datasources\/proxy\/([\d]+|uid\/[\w]+)\/?`) +var proxyPathRegexp = regexp.MustCompile(`^\/api\/datasources\/proxy\/([\d]+|uid\/[\w-]+)\/?`) func extractProxyPath(originalRawPath string) string { return proxyPathRegexp.ReplaceAllString(originalRawPath, "") diff --git a/pkg/services/datasourceproxy/datasourceproxy_test.go b/pkg/services/datasourceproxy/datasourceproxy_test.go index 6567ba579c5..57da4aa33c0 100644 --- a/pkg/services/datasourceproxy/datasourceproxy_test.go +++ b/pkg/services/datasourceproxy/datasourceproxy_test.go @@ -32,6 +32,14 @@ func TestDataProxy(t *testing.T) { "/api/datasources/proxy/uid/26MI0wZ7k/some/thing", "some/thing", }, + { + "/api/datasources/proxy/uid/pUWo-no4k/search", + "search", + }, + { + "/api/datasources/proxy/uid/pUWo_no4k/search", + "search", + }, { "/api/datasources/proxy/uid/26MI0wZ7k/api/services/afsd%2Fafsd/operations", "api/services/afsd%2Fafsd/operations",