Skip to content

Commit

Permalink
fix: prevent url.parse to set path option (#1871)
Browse files Browse the repository at this point in the history
* fix: prevent url.parse to set `path` option

Fixes #1870

* fix: add missing auth

* fix: add test
  • Loading branch information
robertsLando committed May 23, 2024
1 parent 52e0e70 commit de0174f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ function connect(
parsed.port = Number(parsed.port)
}

opts = { ...parsed, ...opts } as IClientOptions
opts = {
...{
port: parsed.port,
host: parsed.hostname,
protocol: parsed.protocol,
query: parsed.query,
auth: parsed.auth,
},
...opts,
} as IClientOptions

if (opts.protocol === null) {
throw new Error('Missing protocol')
Expand Down
9 changes: 9 additions & 0 deletions test/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ describe('mqtt', () => {
c.end((err) => done(err))
})

it('should not set `path` when parsing url', function _test(t, done) {
const c = mqtt.connect('mqtt://[::1]')

c.should.be.instanceOf(mqtt.MqttClient)
c.options.should.not.have.property('path')
c.options.should.have.property('host', '::1')
c.end((err) => done(err))
})

it('should return an MqttClient with username and password options set', function _test(t, done) {
const c = mqtt.connect('mqtt://user@localhost:1883')

Expand Down

0 comments on commit de0174f

Please sign in to comment.