escape response because people use nosql like apes
This commit is contained in:
@@ -311,7 +311,9 @@ serialize_item_to_builder :: proc(b: ^strings.Builder, item: Item) {
|
||||
if i > 0 {
|
||||
strings.write_string(b, ",")
|
||||
}
|
||||
fmt.sbprintf(b, `"%s":`, key)
|
||||
//fmt.sbprintf(b, `"%s":`, key)
|
||||
write_string_escaped(b, key)
|
||||
strings.write_string(b, ":")
|
||||
value := item[key]
|
||||
serialize_attribute_value(b, value)
|
||||
}
|
||||
@@ -323,7 +325,8 @@ serialize_attribute_value :: proc(b: ^strings.Builder, attr: Attribute_Value) {
|
||||
switch v in attr {
|
||||
case String:
|
||||
strings.write_string(b, `{"S":"`)
|
||||
strings.write_string(b, string(v))
|
||||
//strings.write_string(b, string(v))
|
||||
write_string_escaped(b, string(v))
|
||||
strings.write_string(b, `"}`)
|
||||
|
||||
case DDB_Number:
|
||||
@@ -351,7 +354,8 @@ serialize_attribute_value :: proc(b: ^strings.Builder, attr: Attribute_Value) {
|
||||
if i > 0 {
|
||||
strings.write_string(b, ",")
|
||||
}
|
||||
fmt.sbprintf(b, `"%s"`, s)
|
||||
//fmt.sbprintf(b, `"%s"`, s)
|
||||
write_string_escaped(b, s)
|
||||
}
|
||||
strings.write_string(b, "]}")
|
||||
|
||||
@@ -403,7 +407,9 @@ serialize_attribute_value :: proc(b: ^strings.Builder, attr: Attribute_Value) {
|
||||
if i > 0 {
|
||||
strings.write_string(b, ",")
|
||||
}
|
||||
fmt.sbprintf(b, `"%s":`, key)
|
||||
//fmt.sbprintf(b, `"%s":`, key)
|
||||
write_string_escaped(b, key)
|
||||
strings.write_string(b, ":")
|
||||
value := v[key]
|
||||
serialize_attribute_value(b, value)
|
||||
}
|
||||
@@ -412,6 +418,29 @@ serialize_attribute_value :: proc(b: ^strings.Builder, attr: Attribute_Value) {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to handle escaping json strings jammed into the db
|
||||
write_string_escaped :: proc(b: ^strings.Builder, s: string) {
|
||||
strings.write_byte(b, '"')
|
||||
for ch in transmute([]byte)s {
|
||||
switch ch {
|
||||
case '"': strings.write_string(b, `\"`)
|
||||
case '\\': strings.write_string(b, `\\`)
|
||||
case '\n': strings.write_string(b, `\n`)
|
||||
case '\r': strings.write_string(b, `\r`)
|
||||
case '\t': strings.write_string(b, `\t`)
|
||||
case '\b': strings.write_string(b, `\b`)
|
||||
case '\x0C': strings.write_string(b, `\f`)
|
||||
case:
|
||||
if ch < 0x20 {
|
||||
fmt.sbprintf(b, `\u%04x`, int(ch))
|
||||
} else {
|
||||
strings.write_byte(b, ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
strings.write_byte(b, '"')
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Request Parsing Helpers
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user