Skip to content

Commit

Permalink
More robust field name pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Jundt committed Sep 15, 2016
1 parent d4425da commit 660d740
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/vcard/bnf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})*/

# <"> <Any character except CTLs, DQUOTE> <">
QSTR = /"([^"]*)"/
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/non_standard_name.vcard
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN:VCARD
f#oo/ba;r+test:something
X-messaging/xmpp-All:[email protected]
X-LOTUS-CHILD_UID:1234
X-GOOGLE TALK:2345
END:VCARD
12 changes: 12 additions & 0 deletions test/vcard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]", 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

0 comments on commit 660d740

Please sign in to comment.