fix: factually correct escpaing in sqlite

This commit is contained in:
Antonio
2025-12-25 14:19:30 -04:00
parent 12ff5ab864
commit ca38f3ebc3
+49 -17
View File
@@ -785,36 +785,68 @@ func quoteStringValue(buf []byte, s string, flavor Flavor) []byte {
for ; sz != 0; r, sz = utf8.DecodeRuneInString(s) {
switch r {
case '\x00':
buf = append(buf, "\\0"...)
switch flavor {
case SQLite: // SQLite doesn't support \0
buf = append(buf, `'||char(0)||'`...)
default:
buf = append(buf, `\0`...)
}
case '\b':
buf = append(buf, "\\b"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\b')
default:
buf = append(buf, `\b`...)
}
case '\n':
buf = append(buf, "\\n"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\n')
default:
buf = append(buf, `\n`...)
}
case '\r':
buf = append(buf, "\\r"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\r')
default:
buf = append(buf, `\r`...)
}
case '\t':
buf = append(buf, "\\t"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\t')
default:
buf = append(buf, `\t`...)
}
case '\x1a':
buf = append(buf, "\\Z"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\x1a')
default:
buf = append(buf, `\Z`...)
}
case '\'':
switch flavor {
case SQLite, CQL:
buf = append(buf, "''"...)
default:
buf = append(buf, "\\'"...)
buf = append(buf, `\'`...)
}
case '"':
buf = append(buf, "\\\""...)
switch flavor {
case SQLite: // SQLite Supports direct use of " inside strings
buf = append(buf, '"')
default:
buf = append(buf, `\"`...)
}
case '\\':
buf = append(buf, "\\\\"...)
switch flavor {
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
buf = append(buf, '\\')
default:
buf = append(buf, `\\`...)
}
default:
buf = append(buf, s[:sz]...)
}