sam-github / vpim

vCard and iCalendar support for ruby
http://vpim.rubyforge.org/
Other
142 stars 69 forks source link

ADR fields with quoted-printable encoding not decoded #12

Closed RandomCore closed 10 years ago

RandomCore commented 10 years ago

Crossposted from vcard on request of qoobaa.

I produced an Android vCard export; here's an excerpt:

BEGIN:VCARD VERSION:2.1 FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=65=66=67=20=68=69=70 ADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;=53=74=65=72=6E=73=74=72=61=C3=9F=65=20=31=30;=46=72=61=6E=6B=66=75=72=74;=48=65=73=73=65=6E;=36=30=33=31=38;=44=65=75=74=73=63=68=6C=61=6E=64 END:VCARD

As you will notice vcard will not decode the address field parameters (street, postalcode, etc.) because it uses the values_raw to split the parameters instead of the values (Method Address.decode(card, field) ):

parts = ::Vcard.decode_text_list(field.value_raw, ";")

After I changed it to use field.value instead it worked as expected.

sam-github commented 10 years ago

Doesn't look like "as expected" to me. The purpose of quoting is to HIDE special characters, like ;, from the decoder.

RandomCore commented 10 years ago

First, I was told to crosspost the issue here. It was originally coming as an issue with vcard. See https://github.com/qoobaa/vcard/issue/22 I checked the issue with vcard and, before crossposting here, I looked, if the same line was in vpim. It is. (I did check it now and the result is the same).

Second, I know that there is no char in the address that needs hiding but that's not the question in this issue. The example came from an Android phone (v4.1.2). So it is genuine and should be decoded. The strange encoding might come from the fact, that the fullname line from the complete entry has a German umlaut in it. Anyway, the real question here is: how is Quoted-printable encoding done for ADR fields?

If the example above has a correct encoding of an ADR line, the decoding has to be the string something like Sternstraße 10;Frankfurt;Hessen;60318;Deutschland and not =53=74=65=72=6E=73=74=72=61=C3=9F=65=20=31=30;=46=72=61=6E=6B=66=75=72=74;=48=65=73=73=65=6E;=36=30=33=31=38;=44=65=75=74=73=63=68=6C=61=6E=64 which is what vcard produced. Maybe vpim

I hope this clears it up a bit.

sam-github commented 10 years ago

Just because it came from a phone doesn't mean that is compliant, but in fairness, spec is horrible, and does not actually specify when the decoding happens for values.

Since quoted printable isn't allowed for vCard 3.0, I guess using the decoded value, and attempting to parse as an ADR multi-value should be safe.

I'll accept a PR, please check the tests, too.

RandomCore commented 10 years ago

I (hopefully) initiated a pull request for the change. test/test_vacrd.rb ran fine.