Surreal-Net / Surreal.Net

Database driver for SurrealDB available for REST and RPC sessions.
Apache License 2.0
57 stars 7 forks source link

Bug: REST Driver FormatVarsSlow deletes $ from variables not in vars dictionary #114

Closed Techcraft7 closed 1 year ago

Techcraft7 commented 1 year ago

Describe the bug

When using the REST Driver, any variables in the query that arent in the vars dictionary have their $ symbol removed.

However, this only happens when the vars dictionary is not empty, resulting in a call to FormatVarsSlow.

EX:

LET $x = 5;

With the vars dictionary { ["y"] = 6 }

Would become:

LET x = 5;

This causes the query to fail.

This bug appears to be caused by this line. Adding result.Append('$'); before this line might be the solution to this issue.

Steps to reproduce

  1. Create an instance of the REST database driver
  2. Call FormatVarsSlow, the method responsible for replacing variables in the query.
    string? result = typeof(DatabaseRest).GetMethod(
    "FormatVarsSlow",
    System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
    // "db" is the driver instance
    ?.Invoke(db, new object[]
    {
        @"LET $x = 5",
        new Dictionary<string, object?>()
        {
            ["y"] = 6
        }
    }) as string;
  3. The value of result will be "LET x = 5"

Expected behaviour

IDatabase.Query should not do anything to any variables that are not in the vars dictionary parameter.

Surreal.NET driver version

1.0.8

SurrealDB version

v1.0.0-beta.8

Is there an existing issue for this?

ProphetLamb commented 1 year ago

Thanks a lot for the PR!

Techcraft7 commented 1 year ago

oops forgot to close this fixed with #115