JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

Escaping backslashes in headers #77

Open onemanclapping opened 6 years ago

onemanclapping commented 6 years ago

I have a use case where I need to send a backslash in a header of a SUBSCRIBE frame.

The STOMP specification states that:

C style string literal escapes are used to encode any colons and newlines that are found within the UTF-8 encoded headers. When decoding frame headers, the following transformations MUST be applied:

\n (octet 92 and 110) translates to newline (octet 10)
\c (octet 92 and 99) translates to : (octet 58)
\\ (octet 92 and 92) translates to \ (octet 92)

Currently, webstomp-client (as well as jmesnil's stomp-websocket) does not escape \ into \\:

Object.keys(this.headers).forEach(name => {
    let value = this.headers[name];
    lines.push(`${name}:${value}`);
});

What are your thoughts on this? Shouldn't this be implemented in the library, since it's something defined in the specification, and should therefore not a responsability of the client application?

Thanks.

JSteunou commented 6 years ago

I agree. Up to make a PR ?

leandrogaspar commented 5 years ago

@JSteunou @onemanclapping do you guys mind if I give it a try?

JSteunou commented 5 years ago

You are more than welcome