Escape record id parts like ⟨this⟩ rather than this

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-06 10:08:11 +01:00
parent 2d076c79a7
commit 073c15b826
3 changed files with 17 additions and 4 deletions

View file

@ -1,5 +1,8 @@
use crate::sql::common::val_char;
const BRACKET_L: char = '⟨';
const BRACKET_R: char = '⟩';
const DOUBLE: char = '"';
const DOUBLE_ESC: &str = r#"\""#;
@ -11,6 +14,16 @@ pub fn escape_strand(s: &str) -> String {
format!("{}{}{}", DOUBLE, s, DOUBLE)
}
#[inline]
pub fn escape_id(s: &str) -> String {
for x in s.chars() {
if !val_char(x) {
return format!("{}{}{}", BRACKET_L, s, BRACKET_R);
}
}
s.to_owned()
}
#[inline]
pub fn escape_key(s: &str) -> String {
for x in s.chars() {

View file

@ -1,6 +1,6 @@
use crate::cnf::ID_CHARS;
use crate::sql::error::IResult;
use crate::sql::escape::escape_ident;
use crate::sql::escape::escape_id;
use crate::sql::ident::ident_raw;
use crate::sql::number::integer;
use nanoid::nanoid;
@ -55,7 +55,7 @@ impl fmt::Display for Id {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Id::Number(v) => write!(f, "{}", v),
Id::String(v) => write!(f, "{}", escape_ident(v)),
Id::String(v) => write!(f, "{}", escape_id(v)),
}
}
}

View file

@ -1,5 +1,5 @@
use crate::sql::error::IResult;
use crate::sql::escape::escape_ident;
use crate::sql::escape::escape_id;
use crate::sql::id::{id, Id};
use crate::sql::ident::ident_raw;
use crate::sql::serde::is_internal_serialization;
@ -54,7 +54,7 @@ impl Thing {
impl fmt::Display for Thing {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}:{}", escape_ident(&self.tb), self.id)
write!(f, "{}:{}", escape_id(&self.tb), self.id)
}
}