stomp-js / stomp-websocket

Stomp client for Web browsers and node.js apps
https://stomp-js.github.io/stomp-websocket/
Apache License 2.0
141 stars 36 forks source link

No support of STOMP 1.2 value escaping #16

Closed Toparvion closed 6 years ago

Toparvion commented 7 years ago

Hello, I've started to use your branch of JS stomp-websocket library (thanks for the great job, BTW) and found out that there is a certain discrepancy with protocol spec. Namely, STOMP 1.2 specification states that almost all frames must not only be encoded to UTF-8 but also must be escaped:

All frames except the CONNECT and CONNECTED frames will also escape any carriage return, line feed or colon found in the resulting UTF-8 encoded headers.

In my project I send messages that have colon in their destination header. The colon comes from server to client in the form of \c symbols that is totally right according to STOMP 1.2 spec:

\c (octet 92 and 99) translates to : (octet 58)

But the client does not convert it back to colon and thus misses the messages with the following record in log:

Unhandled received MESSAGE: MESSAGE

Can you please enhance the library with (un)escaping capability?

kum-deepak commented 7 years ago

Indeed it needs to be implemented. Give me few days while I figure out the best way to do it.

I will first release it is a branch so that you can also test before I push it as a general release.

Toparvion commented 7 years ago

Ok, @kum-deepak, thanks! I'm looking forward to become the first user (and tester) of this feature :blush:

Meanwhile, I've temporarily solved the problem by adding a naive function to the Frame object:

    Frame.unescape = function (value) {
        return value
            .replace(new RegExp("\\r", 'g'), '\r')
            .replace(new RegExp("\\c", 'g'), ':')
            .replace(new RegExp("\\n", 'g'), '\n')
            .replace(new RegExp("\\\\", 'g'), '\\')
    };

and calling it in appropriate command handlers like:

              case "MESSAGE":
                subscription = Frame.unescape(frame.headers.subscription);
                onreceive = _this.subscriptions[subscription] || _this.onreceive;   // this is where the error stepped in
kum-deepak commented 7 years ago

Please check branch header_escape. Test it out, if possible check the code diff as well.

Toparvion commented 7 years ago

@kum-deepak, answered in PR #17.

kum-deepak commented 6 years ago

Will close after release of a new version.

kum-deepak commented 6 years ago

Released new version 3.1.2.

Toparvion commented 6 years ago

@kum-deepak, can you please deploy this version as webjar?

kum-deepak commented 6 years ago

Deployed. In future you can do it yourself. It does not ask for any authentication - when picking from npm.