Do not ever quote asterisk symbol. Fixes #1780 #1781

Merged
lunny merged 1 commits from lafriks-fork/xorm:fix/asterisk_escape into master 2020-09-06 08:24:20 +00:00
2 changed files with 10 additions and 7 deletions

View File

@ -82,9 +82,7 @@ func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error {
return err
}
}
if s != "*" {
q.QuoteTo(b, strings.TrimSpace(s))
}
q.QuoteTo(b, strings.TrimSpace(s))
}
return nil
}
@ -143,7 +141,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
}
isReserved := q.IsReserved(realWord)
if isReserved {
if isReserved && realWord != "*" {
Review

But when realWord is *, q.IsReserved will always return false ?

But when realWord is `*`, q.IsReserved will always return `false` ?
if err := buf.WriteByte(q.Prefix); err != nil {
return err
}
@ -151,7 +149,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
if _, err := buf.WriteString(realWord); err != nil {
return err
}
if isReserved {
if isReserved && realWord != "*" {
return buf.WriteByte(q.Suffix)
}

View File

@ -22,6 +22,7 @@ func TestAlwaysQuoteTo(t *testing.T) {
{"[mytable]", "`mytable`"},
{"[mytable]", `[mytable]`},
{`["mytable"]`, `"mytable"`},
{`[mytable].*`, `[mytable].*`},
{"[myschema].[mytable]", "myschema.mytable"},
{"[myschema].[mytable]", "`myschema`.mytable"},
{"[myschema].[mytable]", "myschema.`mytable`"},
@ -65,6 +66,7 @@ func TestReversedQuoteTo(t *testing.T) {
{"[mytable]", "mytable"},
{"[mytable]", "`mytable`"},
{"[mytable]", `[mytable]`},
{"[mytable].*", `[mytable].*`},
{`"mytable"`, `"mytable"`},
{"myschema.[mytable]", "myschema.mytable"},
{"myschema.[mytable]", "`myschema`.mytable"},
@ -98,6 +100,7 @@ func TestNoQuoteTo(t *testing.T) {
{"mytable", "mytable"},
{"mytable", "`mytable`"},
{"mytable", `[mytable]`},
{"mytable.*", `[mytable].*`},
{`"mytable"`, `"mytable"`},
{"myschema.mytable", "myschema.mytable"},
{"myschema.mytable", "`myschema`.mytable"},
@ -127,6 +130,8 @@ func TestJoin(t *testing.T) {
assert.EqualValues(t, "[a],[b]", quoter.Join([]string{"a", " b"}, ","))
assert.EqualValues(t, "[a].*,[b].[c]", quoter.Join([]string{"a.*", " b.c"}, ","))
assert.EqualValues(t, "[f1], [f2], [f3]", quoter.Join(cols, ", "))
quoter.IsReserved = AlwaysNoReserve
@ -134,11 +139,11 @@ func TestJoin(t *testing.T) {
}
func TestStrings(t *testing.T) {
cols := []string{"f1", "f2", "t3.f3"}
cols := []string{"f1", "f2", "t3.f3", "t4.*"}
quoter := Quoter{'[', ']', AlwaysReserve}
quotedCols := quoter.Strings(cols)
assert.EqualValues(t, []string{"[f1]", "[f2]", "[t3].[f3]"}, quotedCols)
assert.EqualValues(t, []string{"[f1]", "[f2]", "[t3].[f3]", "[t4].*"}, quotedCols)
}
func TestTrim(t *testing.T) {