Skip to content

Commit

Permalink
Strip trailing / from URIs before connecting (#238)
Browse files Browse the repository at this point in the history
## Description of Changes
We were not stripping `/` from the end of URIs provided to `Connect`. We
manually append `/...` to the provided addresses, so if we don't start
by stripping trailing `/`s, we end up with `//` in the URI and we get
errors.

Addresses part of
clockworklabs/SpacetimeDB#1551.

## API

No breaking  changes. This fixes an error case.

## Requires SpacetimeDB PRs
None

## Testsuite
SpacetimeDB branch name: master

## Testing
- [x] Tested the quickstart chat client with a host containing a
trailing `/`
```
# start a server, publish the module, send some input
# I also updated one line in `client.csproj` to use `Net8.0` because I no longer have `Net7.0` installed

$ cd examples~/quickstart/client

$ dotnet run
[I] SpacetimeDBClient: Connecting to ws://localhost:3000 quickstart-chat
C200098E is online
Connected
C2007471: hello
C2007471: godo
C2007471: asdf

$ sed -i 's/localhost:3000/localhost:3000\//' Program.cs

$ dotnet run
[I] SpacetimeDBClient: Connecting to ws://localhost:3000 quickstart-chat
C2000601 is online
Connected
C2007471: hello
C2007471: godo
C2007471: asdf

$ git diff
diff --git a/examples~/quickstart/client/Program.cs b/examples~/quickstart/client/Program.cs
index 9eb43b1..289e736 100644
--- a/examples~/quickstart/client/Program.cs
+++ b/examples~/quickstart/client/Program.cs
@@ -7,8 +7,8 @@ using System.Threading;
 using SpacetimeDB;
 using SpacetimeDB.Types;
 
-const string HOST = "http://localhost:3000";
-const string DBNAME = "chatqs";
+const string HOST = "http://localhost:3000/";
+const string DBNAME = "quickstart-chat";
 
 // our local client SpacetimeDB identity
 Identity? local_identity = null;
diff --git a/examples~/quickstart/client/client.csproj b/examples~/quickstart/client/client.csproj
index 48917cc..ab7ce44 100644
--- a/examples~/quickstart/client/client.csproj
+++ b/examples~/quickstart/client/client.csproj
@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net7.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <CheckEolTargetFramework>false</CheckEolTargetFramework>
     <ImplicitUsings>disable</ImplicitUsings>
     <Nullable>enable</Nullable>
```

---------

Co-authored-by: Zeke Foppa <[email protected]>
  • Loading branch information
bfops and bfops authored Feb 11, 2025
1 parent 19c3e75 commit 2f55054
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ void IDbConnection.Connect(string? token, string uri, string addressOrName, Comp
{
uri = $"ws://{uri}";
}
// Things fail surprisingly if we have a trailing slash, because we later manually append strings
// like `/foo` and then end up with `//` in the URI.
uri = uri.TrimEnd('/');

Log.Info($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
if (!IsTesting)
Expand Down

0 comments on commit 2f55054

Please sign in to comment.