mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
refs #19. print normal $ sign in format string if $ syntax is wrong
This commit is contained in:
@@ -95,20 +95,24 @@ func (args *Args) CompileWithFlavor(format string, flavor Flavor, intialValue ..
|
||||
|
||||
format = format[idx+1:]
|
||||
|
||||
// Should not happen.
|
||||
// Treat the $ at the end of format is a normal $ rune.
|
||||
if len(format) == 0 {
|
||||
buf.WriteRune('$')
|
||||
break
|
||||
}
|
||||
|
||||
if format[0] == '$' {
|
||||
if r := format[0]; r == '$' {
|
||||
buf.WriteRune('$')
|
||||
format = format[1:]
|
||||
} else if format[0] == '{' {
|
||||
} else if r == '{' {
|
||||
format, values = args.compileNamed(buf, flavor, format, values)
|
||||
} else if !args.onlyNamed && '0' <= format[0] && format[0] <= '9' {
|
||||
} else if !args.onlyNamed && '0' <= r && r <= '9' {
|
||||
format, values, offset = args.compileDigits(buf, flavor, format, values, offset)
|
||||
} else if !args.onlyNamed && format[0] == '?' {
|
||||
} else if !args.onlyNamed && r == '?' {
|
||||
format, values, offset = args.compileSuccessive(buf, flavor, format[1:], values, offset)
|
||||
} else {
|
||||
// For unknown $ expression format, treat it as a normal $ rune.
|
||||
buf.WriteRune('$')
|
||||
}
|
||||
|
||||
idx = strings.IndexRune(format, '$')
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func TestArgs(t *testing.T) {
|
||||
"abc ? def\n[789]": {"abc ${s} def", Named("s", 789)},
|
||||
"abc def \n[]": {"abc ${unknown} def ", 123},
|
||||
"abc $ def\n[]": {"abc $$ def", 123},
|
||||
"abcdef\n[]": {"abcdef$", 123},
|
||||
"abcdef$\n[]": {"abcdef$", 123},
|
||||
"abc ? ? ? ? def\n[123 456 123 456]": {"abc $? $? $0 $? def", 123, 456, 789},
|
||||
"abc ? raw ? raw def\n[123 123]": {"abc $? $? $0 $? def", 123, Raw("raw"), 789},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user