Escape record id parts like ⟨this⟩ rather than this
This commit is contained in:
parent
2d076c79a7
commit
073c15b826
3 changed files with 17 additions and 4 deletions
|
@ -1,5 +1,8 @@
|
||||||
use crate::sql::common::val_char;
|
use crate::sql::common::val_char;
|
||||||
|
|
||||||
|
const BRACKET_L: char = '⟨';
|
||||||
|
const BRACKET_R: char = '⟩';
|
||||||
|
|
||||||
const DOUBLE: char = '"';
|
const DOUBLE: char = '"';
|
||||||
const DOUBLE_ESC: &str = r#"\""#;
|
const DOUBLE_ESC: &str = r#"\""#;
|
||||||
|
|
||||||
|
@ -11,6 +14,16 @@ pub fn escape_strand(s: &str) -> String {
|
||||||
format!("{}{}{}", DOUBLE, s, DOUBLE)
|
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]
|
#[inline]
|
||||||
pub fn escape_key(s: &str) -> String {
|
pub fn escape_key(s: &str) -> String {
|
||||||
for x in s.chars() {
|
for x in s.chars() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::cnf::ID_CHARS;
|
use crate::cnf::ID_CHARS;
|
||||||
use crate::sql::error::IResult;
|
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::ident::ident_raw;
|
||||||
use crate::sql::number::integer;
|
use crate::sql::number::integer;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
|
@ -55,7 +55,7 @@ impl fmt::Display for Id {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Id::Number(v) => write!(f, "{}", v),
|
Id::Number(v) => write!(f, "{}", v),
|
||||||
Id::String(v) => write!(f, "{}", escape_ident(v)),
|
Id::String(v) => write!(f, "{}", escape_id(v)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::sql::error::IResult;
|
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::id::{id, Id};
|
||||||
use crate::sql::ident::ident_raw;
|
use crate::sql::ident::ident_raw;
|
||||||
use crate::sql::serde::is_internal_serialization;
|
use crate::sql::serde::is_internal_serialization;
|
||||||
|
@ -54,7 +54,7 @@ impl Thing {
|
||||||
|
|
||||||
impl fmt::Display for Thing {
|
impl fmt::Display for Thing {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue