Skip to content

Commit

Permalink
Fixed string quoting bug and tests (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: ohad bitton <[email protected]>
  • Loading branch information
AsafMah and ohadbitt authored Nov 29, 2023
1 parent 73fa835 commit c557823
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Changed (BREAKING)

- Queries are no longer progressive by default.
- `ResultsProgressiveDisable()` has been removed.
- Use `ResultsProgressiveEnabled()` to enable progressive queries.

### Fixed

- String quoting in default value of query parameters

## [0.14.2] - 2023-11-08

Expand All @@ -22,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.14.1] - 2023-09-27

### Added

- Support new playfab domain

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion kusto/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ These provide injection safe querying for data retrieval and insertion.
import (
"encoding/json"
"fmt"
"github.com/Azure/azure-kusto-go/kusto/kql"
"math/big"
"sort"
"strings"
Expand Down Expand Up @@ -183,7 +184,7 @@ func (p ParamType) string() string {
return p.name + ":string"
}
v := p.Default.(string)
return fmt.Sprintf(`%s:string = "%s"`, p.name, v) // TODO - escape the string when we have the functionaity
return fmt.Sprintf(`%s:string = %s`, p.name, kql.QuoteString(v, false))
case types.Timespan:
if p.Default == nil {
return p.name + ":timespan"
Expand Down
15 changes: 12 additions & 3 deletions kusto/query_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,23 @@ func TestParamType(t *testing.T) {
},
wantStr: "my_value:string = \"hello\"",
},
{
desc: "Quoted value default for types.String",
param: ParamType{
Type: types.String,
Default: "h\\el\"l\t\no",
name: "my_value",
},
wantStr: `my_value:string = "h\\el\"l\t\no"`,
},
{
desc: "Success Default for types.Timespan",
param: ParamType{
Type: types.Timespan,
Default: duration,
name: "my_value:timespan = timespan(03.01:03:00)",
name: "my_value",
},
wantStr: "my_value:timespan = timespan(1000)",
wantStr: "my_value:timespan = timespan(01:03:02)",
},
{
desc: "Success Default for types.Decimal",
Expand Down Expand Up @@ -267,7 +276,7 @@ func TestParamType(t *testing.T) {
assert.NoError(t, err)
case err != nil && !test.err:
assert.Error(t, err)
case err != nil:
case err == nil:
if test.panic {
assert.Panicsf(t, func() { test.param.string() }, "panic: internal bug: ParamType.string() called without a call to .validate()")
return
Expand Down

0 comments on commit c557823

Please sign in to comment.