Encoding line breaks for things like Address and Notes #9

Closed
brendon opened this Issue Apr 3, 2013 · 8 comments

3 participants

@brendon

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')
@qoobaa
Owner

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

@m1foley
Collaborator

@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.

@brendon

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 :)

@brendon

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
@m1foley
Collaborator

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

@brendon brendon referenced this issue Jun 18, 2013
Merged

Newlines bug #13

@brendon

Thanks @m1foley, got one for you there now.

@qoobaa
Owner

Is this fixed now?

@brendon

Yes all fixed :)

@brendon brendon closed this Jun 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment