mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
@@ -118,10 +118,24 @@ when false:
|
||||
|
||||
proc dbQuote*(s: string): string =
|
||||
## DB quotes the string.
|
||||
result = "'"
|
||||
result = newStringOfCap(s.len + 2)
|
||||
result.add "'"
|
||||
for c in items(s):
|
||||
if c == '\'': add(result, "''")
|
||||
else: add(result, c)
|
||||
# see https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html#mysql-escaping
|
||||
case c
|
||||
of '\0': result.add "\\0"
|
||||
of '\b': result.add "\\b"
|
||||
of '\t': result.add "\\t"
|
||||
of '\l': result.add "\\n"
|
||||
of '\r': result.add "\\r"
|
||||
of '\x1a': result.add "\\Z"
|
||||
of '"': result.add "\\\""
|
||||
of '%': result.add "\\%"
|
||||
of '\'': result.add "\\'"
|
||||
of '\\': result.add "\\\\"
|
||||
of '_': result.add "\\_"
|
||||
of Letters+Digits: result.add c
|
||||
else: result.add "\\" & $ord(c)
|
||||
add(result, '\'')
|
||||
|
||||
proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string =
|
||||
|
||||
Reference in New Issue
Block a user