Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Fixed issue where special characters in URL paths (like #) were being treated as URL fragments. Added proper URL encoding for path components in HTTP requests

### 6.4.0 / 2025-04-30
* Added support for Notetaker APIs
* Added support for Notetaker via the calendar and event APIs
Expand Down
6 changes: 6 additions & 0 deletions lib/nylas/handler/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ def throw_error(response, status_code, headers = nil)
# @param query [Hash] The query parameters to add to the URL.
# @return [String] Processed URL, including query params.
def build_url(url, query = nil)
if url
base_url, *path_parts = url.split("/")
encoded_path = [base_url, *path_parts.map { |part| URI.encode_www_form_component(part) }].join("/")
url = encoded_path
end

unless query.nil? || query.empty?
uri = URI.parse(url)
uri = build_query(uri, query)
Expand Down
15 changes: 15 additions & 0 deletions spec/nylas/handler/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ class TestHttpClient

expect(final_uri.to_s).to eq("https://test.api.nylas.com/foo?foo=bar&list=a&list=b&list=c&map=key1%3Avalue1&map=key2%3Avalue2")
end

it "properly encodes special characters in the path" do
uri = "https://test.api.nylas.com/v3/grants/p#weather@group.v.calendar.google.com/calendars"
final_uri = http_client.send(:build_url, uri)

expect(final_uri.to_s).to eq("https://test.api.nylas.com/v3/grants/p%23weather%40group.v.calendar.google.com/calendars")
end

it "properly encodes special characters in the path with query parameters" do
uri = "https://test.api.nylas.com/v3/grants/p#weather@group.v.calendar.google.com/calendars"
params = { foo: "bar" }
final_uri = http_client.send(:build_url, uri, params)

expect(final_uri.to_s).to eq("https://test.api.nylas.com/v3/grants/p%23weather%40group.v.calendar.google.com/calendars?foo=bar")
end
end

describe "#throw_error" do
Expand Down
Loading