Unified · Split
| @@ -35,6 +35,12 @@ describe("endpointForTelemetry", () => { · 34 unmodified lines | ||
| 35 | 35 | ); |
| 36 | 36 | }); |
| 37 | 37 | |
| 38 | + it("does not URL-normalize a credential-free endpoint", () => { | |
| 39 | + // A bare origin round-tripped through URL gains a trailing slash; the | |
| 40 | + // stamped attribute must stay byte-identical to the configured endpoint. | |
| 41 | + expect(endpointForTelemetry("http://127.0.0.1:55003")).toBe("http://127.0.0.1:55003"); | |
| 42 | + }); | |
| 43 | + | |
| 38 | 44 | it("returns unparseable input as-is", () => { |
| 39 | 45 | expect(endpointForTelemetry("not a url")).toBe("not a url"); |
| 40 | 46 | }); |
| @@ -23,6 +23,12 @@ · 22 unmodified lines | ||
| 23 | 23 | export const endpointForTelemetry = (endpoint: string): string => { |
| 24 | 24 | if (!URL.canParse(endpoint)) return endpoint; |
| 25 | 25 | const url = new URL(endpoint); |
| 26 | + // A clean endpoint is returned verbatim: round-tripping through URL | |
| 27 | + // normalizes (e.g. appends a trailing slash to an origin), which would make | |
| 28 | + // the stamped attribute diverge from the configured value. | |
| 29 | + if (url.search === "" && url.hash === "" && url.username === "" && url.password === "") { | |
| 30 | + return endpoint; | |
| 31 | + } | |
| 26 | 32 | url.search = ""; |
| 27 | 33 | url.hash = ""; |
| 28 | 34 | url.username = ""; |