Skip to content

Commit

Permalink
fix url-encoding of request parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
acarioni committed Aug 24, 2023
1 parent 2dda288 commit e7b115f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/LightstreamerClient/utils/LsRequestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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") ?? ""
}
}
2 changes: 1 addition & 1 deletion Tests/LightstreamerClientTests/LsRequestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
27 changes: 27 additions & 0 deletions Tests/LightstreamerClientTests/SubscriptionWSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e7b115f

Please sign in to comment.