Skip to content

Commit

Permalink
Update Text token for multi-byte characters. (#15)
Browse files Browse the repository at this point in the history
* Update Text token for multi-byte characters.

* Bump patch version.
  • Loading branch information
tmpfs authored Jun 27, 2024
1 parent d7ad8f0 commit 8845d16
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit 8845d16

Please sign in to comment.