Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding line breaks for things like Address and Notes #9

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

Encoding line breaks for things like Address and Notes #9

brendon opened this issue Apr 3, 2013 · 8 comments

Comments

@brendon
Copy link
Collaborator

brendon commented Apr 3, 2013

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
Copy link
Owner

qoobaa commented Apr 3, 2013

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

@m1foley
Copy link
Collaborator

m1foley commented May 28, 2013

@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
Copy link
Collaborator Author

brendon commented Jun 18, 2013

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
Copy link
Collaborator Author

brendon commented Jun 18, 2013

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
Copy link
Collaborator

m1foley commented Jun 18, 2013

@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 mentioned this issue Jun 18, 2013
@brendon
Copy link
Collaborator Author

brendon commented Jun 18, 2013

Thanks @m1foley, got one for you there now.

@qoobaa
Copy link
Owner

qoobaa commented Jun 19, 2013

Is this fixed now?

@brendon
Copy link
Collaborator Author

brendon commented Jun 19, 2013

Yes all fixed :)

@brendon brendon closed this as completed Jun 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants