Skip to content

Instantly share code, notes, and snippets.

@gdchamal
Created May 31, 2019 12:09
Show Gist options
  • Save gdchamal/43c58f9d581cee05c40706692f852373 to your computer and use it in GitHub Desktop.
Save gdchamal/43c58f9d581cee05c40706692f852373 to your computer and use it in GitHub Desktop.
tao~/dev/caliopen/go/src/github.com/emersion/go-vcard(master|✚1) % git diff
diff --git a/decoder.go b/decoder.go
index 1d2153d..37356b9 100644
--- a/decoder.go
+++ b/decoder.go
@@ -108,14 +108,19 @@ func parseLine(l string) (key string, field *Field, err error) {
if err != nil {
return
}
-
if hasParams {
- field.Params, l, err = parseParams(l)
+ i := strings.IndexAny(l, "=")
+ if i >= 0 {
+ field.Params, l, err = parseParams(l)
+ } else {
+ // Surely v2.1 parameter syntax
+ i = strings.IndexAny(l, ":")
+ l = l[i+1:]
+ }
if err != nil {
return
}
}
-
field.Value = parseValue(l)
return
}
@sapiens-sapide
Copy link

this algo won't fix our issue with 2.1. For example, line below, which is not correctly parsed by emersion's pkg, will still not be correctly parsed with our workaround :
email;internet:Emma@tomme.de.savoie

@gdchamal
Copy link
Author

gdchamal commented May 31, 2019

INFO[0000] Found 4 vcards
INFO[0000] Vcard wit fn Emma
INFO[0000] Got contact emma@tomme.de.savoie

I parse correctly this

begin:vcard
fn:Emma
email;internet:Emma@tomme.de.savoie
version:2.1
end:vcard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment