-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix customEndpointAddress parsing in browsers
- Loading branch information
Showing
6 changed files
with
63 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* Parses the host, hostname, and port from an endpoint. | ||
* @param endpoint And endpoint to parse. | ||
* @hidden | ||
* @internal | ||
*/ | ||
export function parseEndpoint(endpoint: string): { host: string; hostname: string; port?: string } { | ||
const hostMatch = endpoint.match(/.*:\/\/([^\/]*)/i); | ||
if (!hostMatch) { | ||
throw new TypeError(`Invalid endpoint missing host: ${endpoint}`); | ||
} | ||
|
||
const [, host] = hostMatch; | ||
const [hostname, port] = host.split(":"); | ||
|
||
return { host, hostname, port }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { parseEndpoint } from "../../src/util/parseEndpoint"; | ||
import chai from "chai"; | ||
const should = chai.should(); | ||
|
||
describe("parseEndpoint", () => { | ||
it("throws an error for invalid inputs", () => { | ||
should.throw(() => parseEndpoint(""), /Invalid endpoint/); | ||
should.throw(() => parseEndpoint("missing-protocol"), /Invalid endpoint/); | ||
should.throw(() => parseEndpoint("//missing-protocol"), /Invalid endpoint/); | ||
}); | ||
|
||
it("extracts host, hostname, and port", () => { | ||
parseEndpoint("sb://test.servicebus.windows.net:5671").should.eql({ | ||
host: "test.servicebus.windows.net:5671", | ||
hostname: "test.servicebus.windows.net", | ||
port: "5671" | ||
} as ReturnType<typeof parseEndpoint>); | ||
|
||
parseEndpoint("https://127.0.0.1:5671").should.eql({ | ||
host: "127.0.0.1:5671", | ||
hostname: "127.0.0.1", | ||
port: "5671" | ||
} as ReturnType<typeof parseEndpoint>); | ||
|
||
parseEndpoint("amqps://127.0.0.1:5671/path/?query=foo").should.eql({ | ||
host: "127.0.0.1:5671", | ||
hostname: "127.0.0.1", | ||
port: "5671" | ||
} as ReturnType<typeof parseEndpoint>); | ||
|
||
parseEndpoint("wss://127.0.0.1/path/?query=foo").should.eql({ | ||
host: "127.0.0.1", | ||
hostname: "127.0.0.1", | ||
port: undefined | ||
} as ReturnType<typeof parseEndpoint>); | ||
}); | ||
}); |