Skip to content

Commit

Permalink
Refactor escape string literal logic to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
psvri committed Jan 5, 2025
1 parent 2d84956 commit a11f4b2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/translate/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ pub fn translate_expr(
}
ast::Literal::String(s) => {
program.emit_insn(Insn::String8 {
value: s[1..s.len() - 1].replace("''", "'").to_string(),
value: sanitize_string(s),
dest: target_register,
});
Ok(target_register)
Expand Down Expand Up @@ -2074,3 +2074,9 @@ pub fn get_name(
_ => fallback(),
}
}

// Sanitaizes a string literal by removing single quote at front and back
// and escaping double single quotes
pub fn sanitize_string(input: &str) -> String {
input[1..input.len() - 1].replace("''", "'").to_string()
}

0 comments on commit a11f4b2

Please sign in to comment.