Skip to content

Commit 3cb4da1

Browse files
authored
Merge branch 'main' into main
2 parents 17571b8 + 65b4f85 commit 3cb4da1

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5858
([#2420](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2420))
5959
- `opentelemetry-instrumentation-asyncio` Check for __name__ attribute in the coroutine
6060
([#2521](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2521))
61+
- `opentelemetry-util-http` Preserve brackets around literal IPv6 hosts ([#2552](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2552))
6162

6263
## Version 1.24.0/0.45b0 (2024-03-28)
6364

util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ def remove_url_credentials(url: str) -> str:
166166
parsed = urlparse(url)
167167
if all([parsed.scheme, parsed.netloc]): # checks for valid url
168168
parsed_url = urlparse(url)
169-
netloc = (
170-
(":".join(((parsed_url.hostname or ""), str(parsed_url.port))))
171-
if parsed_url.port
172-
else (parsed_url.hostname or "")
173-
)
169+
_, _, netloc = parsed.netloc.rpartition("@")
174170
return urlunparse(
175171
(
176172
parsed_url.scheme,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unittest
2+
3+
from opentelemetry.util.http import remove_url_credentials
4+
5+
6+
class TestRemoveUrlCredentials(unittest.TestCase):
7+
def test_remove_no_credentials(self):
8+
url = "http://opentelemetry.io:8080/test/path?query=value"
9+
cleaned_url = remove_url_credentials(url)
10+
self.assertEqual(cleaned_url, url)
11+
12+
def test_remove_credentials(self):
13+
url = "http://someuser:[email protected]:8080/test/path?query=value"
14+
cleaned_url = remove_url_credentials(url)
15+
self.assertEqual(
16+
cleaned_url, "http://opentelemetry.io:8080/test/path?query=value"
17+
)
18+
19+
def test_remove_credentials_ipv4_literal(self):
20+
url = "http://someuser:[email protected]:8080/test/path?query=value"
21+
cleaned_url = remove_url_credentials(url)
22+
self.assertEqual(cleaned_url, "http://127.0.0.1:8080/test/path?query=value")
23+
24+
def test_remove_credentials_ipv6_literal(self):
25+
url = "http://someuser:somepass@[::1]:8080/test/path?query=value"
26+
cleaned_url = remove_url_credentials(url)
27+
self.assertEqual(cleaned_url, "http://[::1]:8080/test/path?query=value")

0 commit comments

Comments
 (0)