Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Feb 21, 2025
1 parent dec7146 commit 7ca0847
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions crates/torii/sqlite/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,46 +71,44 @@ pub fn sanitize_json_string(s: &str) -> String {
} else {
result.push(c);
}
} else {
if c == '\\' {
backslash_count += 1;
result.push('\\');
} else if c == '"' {
if backslash_count % 2 == 0 {
// Unescaped double quote
let mut temp_chars = chars.clone();
// Skip whitespace
while let Some(&next_c) = temp_chars.peek() {
if next_c.is_whitespace() {
temp_chars.next();
} else {
break;
}
}
// Check next non-whitespace character
if let Some(&next_c) = temp_chars.peek() {
if next_c == ':' || next_c == ',' || next_c == '}' {
// End of string
result.push('"');
in_string = false;
} else {
// Internal unescaped quote, escape it
result.push_str("\\\"");
}
} else if c == '\\' {
backslash_count += 1;
result.push('\\');
} else if c == '"' {
if backslash_count % 2 == 0 {
// Unescaped double quote
let mut temp_chars = chars.clone();
// Skip whitespace
while let Some(&next_c) = temp_chars.peek() {
if next_c.is_whitespace() {
temp_chars.next();
} else {
// End of input, treat as end of string
break;
}
}
// Check next non-whitespace character
if let Some(&next_c) = temp_chars.peek() {
if next_c == ':' || next_c == ',' || next_c == '}' {
// End of string
result.push('"');
in_string = false;
} else {
// Internal unescaped quote, escape it
result.push_str("\\\"");
}
} else {
// Escaped double quote, part of string
// End of input, treat as end of string
result.push('"');
in_string = false;

Check warning on line 102 in crates/torii/sqlite/src/utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/sqlite/src/utils.rs#L100-L102

Added lines #L100 - L102 were not covered by tests
}
backslash_count = 0;
} else {
result.push(c);
backslash_count = 0;
// Escaped double quote, part of string
result.push('"');
}
backslash_count = 0;
} else {
result.push(c);
backslash_count = 0;
}
}

Expand Down

0 comments on commit 7ca0847

Please sign in to comment.