From 660d74018fad799a46cfc66cc8508ff9582b50bf Mon Sep 17 00:00:00 2001 From: Oliver Jundt Date: Thu, 15 Sep 2016 02:22:41 +0200 Subject: [PATCH] More robust field name pattern --- lib/vcard/bnf.rb | 3 ++- test/fixtures/non_standard_name.vcard | 6 ++++++ test/vcard_test.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/non_standard_name.vcard diff --git a/lib/vcard/bnf.rb b/lib/vcard/bnf.rb index c396abc..b525165 100644 --- a/lib/vcard/bnf.rb +++ b/lib/vcard/bnf.rb @@ -12,7 +12,8 @@ module Bnf #:nodoc: # Note: "_" allowed because produced by Notes (X-LOTUS-CHILD_UID:) # Note: "/" allowed because produced by KAddressBook (X-messaging/xmpp-All:) # Note: " " allowed because produced by highrisehq.com (X-GOOGLE TALK:) - NAME = /[\w\/-][ \w\/-]*/ + NAME_WORD = /[\w-](?:[^\s.=;:,]*[\w-])?/ + NAME = /#{NAME_WORD}(?: #{NAME_WORD})*/ # <"> <"> QSTR = /"([^"]*)"/ diff --git a/test/fixtures/non_standard_name.vcard b/test/fixtures/non_standard_name.vcard new file mode 100644 index 0000000..624d91e --- /dev/null +++ b/test/fixtures/non_standard_name.vcard @@ -0,0 +1,6 @@ +BEGIN:VCARD +f#oo/ba;r+test:something +X-messaging/xmpp-All:some@jabber.id +X-LOTUS-CHILD_UID:1234 +X-GOOGLE TALK:2345 +END:VCARD diff --git a/test/vcard_test.rb b/test/vcard_test.rb index e508986..1c14794 100644 --- a/test/vcard_test.rb +++ b/test/vcard_test.rb @@ -484,4 +484,16 @@ def test_note card = Vcard::Vcard.decode(card.encode).first assert_equal "line1\n;line2", card.note end + + def test_non_standard_name + card = nil + assert_nothing_thrown { card = Vcard::DirectoryInfo.decode(vcard(:non_standard_name)) } + assert_equal_nospace(vcard(:non_standard_name), card.to_s) + + assert_equal("some@jabber.id", card["X-messaging/xmpp-All"]) + assert_equal("2345", card["X-GOOGLE TALK"]) + assert_equal("something", card["F#OO/BA"]) + assert_equal("1234", card["X-LOTUS-CHILD_UID"]) + assert_equal([], card.groups) + end end