diff --git a/Sources/LightstreamerClient/utils/LsRequestBuilder.swift b/Sources/LightstreamerClient/utils/LsRequestBuilder.swift index 54d2fb8..97d3976 100644 --- a/Sources/LightstreamerClient/utils/LsRequestBuilder.swift +++ b/Sources/LightstreamerClient/utils/LsRequestBuilder.swift @@ -223,6 +223,6 @@ class LsRequestBuilder: CustomStringConvertible { var encodedString: String { var components = URLComponents() components.queryItems = params - return components.percentEncodedQuery ?? "" + return components.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B") ?? "" } } diff --git a/Tests/LightstreamerClientTests/LsRequestBuilderTests.swift b/Tests/LightstreamerClientTests/LsRequestBuilderTests.swift index 0661b65..b016b19 100644 --- a/Tests/LightstreamerClientTests/LsRequestBuilderTests.swift +++ b/Tests/LightstreamerClientTests/LsRequestBuilderTests.swift @@ -7,6 +7,6 @@ final class LsRequestBuilderTests: XCTestCase { let req = LsRequestBuilder() req.addParam("a", "f&=o") req.addParam("b", "b +r") - XCTAssertEqual("a=f%26%3Do&b=b%20+r", req.encodedString) + XCTAssertEqual("a=f%26%3Do&b=b%20%2Br", req.encodedString) } } diff --git a/Tests/LightstreamerClientTests/SubscriptionWSTests.swift b/Tests/LightstreamerClientTests/SubscriptionWSTests.swift index 2135db4..22f3174 100644 --- a/Tests/LightstreamerClientTests/SubscriptionWSTests.swift +++ b/Tests/LightstreamerClientTests/SubscriptionWSTests.swift @@ -30,6 +30,33 @@ final class SubscriptionWSTests: BaseTestCase { """, self.io.trace) } } + + func testSubscribeFieldWithPlus() { + client = newClient("http://server") + client.addDelegate(delegate) + client.connect() + + let sub = Subscription(subscriptionMode: .RAW, item: "item", fields: ["f1+f2"]) + sub.addDelegate(subDelegate) + client.subscribe(sub) + + ws.onOpen() + ws.onText("WSOK") + ws.onText("CONOK,sid,70000,5000,*") + + asyncAssert { + XCTAssertEqual(""" + ws.init http://server/lightstreamer + wsok + create_session\r + LS_cid=\(LS_TEST_CID)&LS_send_sync=false&LS_cause=api + WSOK + CONOK,sid,70000,5000,* + control\r + LS_reqId=1&LS_op=add&LS_subId=1&LS_mode=RAW&LS_group=item&LS_schema=f1%2Bf2&LS_ack=false + """, self.io.trace) + } + } func testSubscribe_adapter_schema_group_selector_buffer() { client = newClient("http://server")