qoobaa/vcard

Encoding line breaks for things like Address and Notes

brendon opened this issue · 8 comments

I found that linebreaks weren't being encoded correctly. Gsubbing my strings with the following worked but would this be better placed inside the library?

.gsub(/\015\012/, "\n").gsub(/\015/, '\n')

The same story - please create a PR for that. :-)

@brendon Just an idea, assuming you'll be looking into this: There might be a more elegant fix in modifying the Bnf Regexps, so I'd try checking that out. In particular, the gsub might be unnecessary if \A and \z are changed to ^ and $ respectively; or if something like \n* is added somewhere.

Hi @m1foley,

Thanks for the suggestion, but I must say I'm completely lost :D I see the file but haven't the first idea where to start to fix this.

I don't see anywhere in there that deals with the encoding of ascii line breaks.

I'm definitely keen to put in a fix for this, but if you were willing to help me get my head around it that would be cool :)

Taking a closer look, I think this is the method that needs modifying to cope with ascii newlines:

def self.encode_text(v) #:nodoc:
  v.to_str.gsub(/([\\,;\n])/) { $1 == "\n" ? "\\n" : "\\#{$1}" }
end

Something like this?

def self.encode_text(v) #:nodoc:
  v.to_str.gsub(/\015\012/, "\n").gsub(/\015/, '\n').gsub(/([\\,;\n])/) { $1 == "\n" ? "\\n" : "\\#{$1}" }
end

@brendon If you create a Pull Request with a failing test, I'll help and we'll come up with a fix together.

Thanks @m1foley, got one for you there now.

Is this fixed now?

Yes all fixed :)