Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Text token for multi-byte characters. #15

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vcard4"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
description = "Fast and correct vCard parser for RFC6350"
repository = "https://github.com/tmpfs/vcard4"
Expand Down
3 changes: 1 addition & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) enum Token {
#[regex("(?i:END:VCARD)")]
End,

#[regex(".", priority = 0)]
#[regex("[\u{00}-\u{7F}]", priority = 0)]
Text,
}

Expand Down Expand Up @@ -153,7 +153,6 @@ impl<'s> VcardParser<'s> {
card: &mut Vcard,
) -> Result<()> {
while let Some(first) = lex.next() {
//println!("{:#?} {}", first, &self.source[lex.span()]);
if first == Ok(Token::End) {
break;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ use anyhow::Result;
use test_helpers::assert_round_trip;
use vcard4::parse;

#[test]
fn parse_multi_byte() -> Result<()> {
let input = r#"BEGIN:VCARD
VERSION:4.0
FN:Mr.
John Qö
Public\,
Esqö
END:VCARD"#;
let mut vcards = parse(input)?;
assert_eq!(1, vcards.len());

let card = vcards.remove(0);
let fname = card.formatted_name.get(0).unwrap();
assert_eq!("Mr. John Qö Public, Esqö", fname.value);
assert_round_trip(&card)?;
Ok(())
}

#[test]
fn parse_folded_space() -> Result<()> {
let input = r#"BEGIN:VCARD
Expand Down
Loading