Skip to content

Commit

Permalink
Change field's to accept symbols as values
Browse files Browse the repository at this point in the history
This works around an issue with JRuby, which accepted symbols being
appended to strings.
  • Loading branch information
Dave Golombek committed Oct 29, 2013
1 parent 15804fb commit 753451e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/vcard/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def Field.encode0(group, name, params={}, value="") # :nodoc:
# [<group>.]<name>;<pname>=<pvalue>,<pvalue>:<value>

if group
line << group << "."
if group.class == Symbol
# Explicitly allow symbols
group = group.to_s
end
line << group.to_str << "."
end

line << name
Expand Down Expand Up @@ -88,7 +92,7 @@ def Field.value_str(value) # :nodoc:
line << value.map { |v| Field.value_str(v) }.join(";")

when Symbol
line << value
line << value.to_s

else
# FIXME - somewhere along here, values with special chars need escaping...
Expand Down
10 changes: 7 additions & 3 deletions test/field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ def test_field_modify
assert_equal("Z.B", f.group)
assert_equal("z.b.NAME:z\n", f.encode)

assert_raises(TypeError) { f.value = :group }
f.value = :group
assert_equal("Z.B.NAME:group\n", f.encode)
f.value = "z"

assert_equal("Z.B", f.group)

assert_equal("z.b.NAME:z\n", f.encode)
assert_equal("Z.B.NAME:z\n", f.encode)

assert_raises(TypeError) { f.group = :group }
f.group = :group
assert_equal("group.NAME:z\n", f.encode)
f.group = "z.b"

assert_equal("z.b.NAME:z\n", f.encode)
assert_equal("Z.B", f.group)
Expand Down

0 comments on commit 753451e

Please sign in to comment.