Skip to content

Space in the subject causes a reply subject to be declared #1433

@Remi-Godin

Description

@Remi-Godin

Observed behavior

When creating a new subject for publishing, if there is a space in the subject, it will use the second part of the subject as a reply subject:

    async fn test_1() {
        let subject = async_nats::Subject::from_static("test.one two");

        let conn = async_nats::connect_with_options(
            "nats://127.0.0.1:43831",
            ConnectOptions::with_user_and_password(
                "username".to_string(),
                "password".to_string(),
            ),
        )
        .await
        .unwrap();

        let res = conn.publish(subject, "Hello world!".into()).await;
        conn.flush().await;
    }

This results in the following message when subscribing through the NATS cli:

[#1] Received on "test.one" with reply "two"
Hello world!

The same behavior can be replicated when using a static string directly in the publish method's arguments.

Expected behavior

Subject creation with invalid characters such as a space should return an error. The API for the crate has an explicit method for publishing a message with a reply subject (publish_with_reply(...)), so having a reply subject be created when using the publish(...) method is unexpected.

Server and client version

nats-server version: 2.11.3
nats version: 0.2.3
async_nats crate version: 0.42.0

Host environment

Pop!_OS 24.04 LTS x86_64
NATS server running on the machine (not in a container)

Steps to reproduce

  1. Run an instance of nats-server
  2. Subscribe to the following subject through the nats cli:
    nats sub test.>
  3. Create a new rust project with the async_nats and tokio crates, and run the following code, using the appropriate username and password for the nats-server instance:
    #[tokio::main]
    async fn main() {
        let subject = async_nats::Subject::from_static("test.one two");
    
        let conn = async_nats::connect_with_options(
            "nats://127.0.0.1:43831",
            async_nats::ConnectOptions::with_user_and_password(
                "local".to_string(),
                "password".to_string(),
            ),
        )
        .await
        .unwrap();
    
        let res = conn.publish(subject, "Hello world!".into()).await;
        conn.flush().await;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSuspected defect such as a bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions