Skip to content

Amqp-0-9-1.js doesn't allow empty string for exchange or routing key #12

Description

@ZachBray

Users of Amqp-0-9-1.js cannot use the default exchange or empty-string routing keys.

This is because the guards are too strict. For example in publishBasic(...):

if (!exchange || typeof exchange != 'string') {
    throw new Error("AmqpChannel.publishBasic(): String parameter \'exchange\' is required");
}
if (!routingKey || typeof routingKey != 'string') {
    throw new Error("AmqpChannel.publishBasic(): String parameter \'routingKey\' is required");
}

They are too strict because the empty-string '' is a falsy value in JavaScript (see: https://developer.mozilla.org/en-US/docs/Glossary/Falsy)

!'' === true

I would suggest changing guards, where the empty-string should be allowed, to something like the following:

if (exchange == null || exchange == undefined || typeof exchange != 'string') {
    throw new Error("AmqpChannel.publishBasic(): String parameter \'exchange\' is required");
}
if (routingKey == null || routingKey == undefined || typeof routingKey != 'string') {
    throw new Error("AmqpChannel.publishBasic(): String parameter \'routingKey\' is required");
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions