Skip to content

Commit

Permalink
Merge 6d32cca into 6876853
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-2956 committed Jul 7, 2022
2 parents 6876853 + 6d32cca commit 06ac82f
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,15 @@ impl<'a> Tokenizer<'a> {
}

Token::Whitespace(Whitespace::Tab) => self.col += 4,
Token::Word(w) if w.quote_style == None => self.col += w.value.len() as u64,
Token::Word(w) if w.quote_style != None => self.col += w.value.len() as u64 + 2,
Token::Number(s, _) => self.col += s.len() as u64,
Token::SingleQuotedString(s) => self.col += s.len() as u64,
Token::Placeholder(s) => self.col += s.len() as u64,
Token::Word(w) if w.quote_style == None => {
self.col += w.value.chars().count() as u64
}
Token::Word(w) if w.quote_style != None => {
self.col += w.value.chars().count() as u64 + 2
}
Token::Number(s, _) => self.col += s.chars().count() as u64,
Token::SingleQuotedString(s) => self.col += s.chars().count() as u64,
Token::Placeholder(s) => self.col += s.chars().count() as u64,
_ => self.col += 1,
}

Expand Down Expand Up @@ -1220,6 +1224,22 @@ mod tests {
);
}

#[test]
fn tokenize_unterminated_string_literal_utf8() {
let sql = String::from("SELECT \"なにか\" FROM Y WHERE \"なにか\" = 'test;");

let dialect = GenericDialect {};
let mut tokenizer = Tokenizer::new(&dialect, &sql);
assert_eq!(
tokenizer.tokenize(),
Err(TokenizerError {
message: "Unterminated string literal".to_string(),
line: 1,
col: 35
})
);
}

#[test]
fn tokenize_invalid_string_cols() {
let sql = String::from("\n\nSELECT * FROM table\tمصطفىh");
Expand Down

0 comments on commit 06ac82f

Please sign in to comment.