Skip to content

Crash if log contains foreign characters(?) #33

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

Closed
fwal opened this issue Oct 14, 2011 · 9 comments
Closed

Crash if log contains foreign characters(?) #33

fwal opened this issue Oct 14, 2011 · 9 comments

Comments

@fwal
Copy link

fwal commented Oct 14, 2011

Hi!

I'm running version 1.2.5 of the gem and 1.9.2 (p290) of ruby.
The following code crashes if the log contains a foreign character in the git log:

require 'git'

# Init git and get log
g = Git.init
log = g.log

changelog = "My changes: \n"

# Now create changelog (and crash)
log.each {|l| 
   changelog += "- " + l.message + "\n")
}

Stack trace:

[...]/gems/git-1.2.5/lib/git/lib.rb:672:in `split': invalid byte sequence in US-ASCII (ArgumentError)
   from [...]/gems/git-1.2.5/lib/git/lib.rb:672:in `command_lines'
   from [...]/gems/git-1.2.5/lib/git/lib.rb:92:in `full_log_commits'
   from [...]/gems/git-1.2.5/lib/git/log.rb:108:in `run_log'
   from [...]/gems/git-1.2.5/lib/git/log.rb:101:in `check_log'
   from [...]/gems/git-1.2.5/lib/git/log.rb:84:in `each'
   from gittest:10:in `<main>'

Any ideas?

@ut
Copy link

ut commented Nov 22, 2011

I can confirm this issue, with version 1.2.5, ruby 1.9.3 and the error message "invalid byte squence in UTF-8"

A possible, imperfect workaround would be to replace in lib/git/lib.rb, line 672..

    def command_lines(cmd, opts = [], chdir = true, redirect = '')
       command(cmd, opts, chdir).split("\n")
    end

...with...

    def command_lines(cmd, opts = [], chdir = true, redirect = '')
      line = command(cmd, opts, chdir)
      if !line.valid_encoding?
        line = line.unpack('C*').pack('U*')
      end
      line.split("\n")
  end

@Bertg
Copy link

Bertg commented Aug 13, 2012

+1 Having the same issue

The solution proposed by @ut works.

@Pilooz
Copy link

Pilooz commented Oct 2, 2012

+1 too, this works fine for me.

@ut
Copy link

ut commented Nov 28, 2012

Thanks for the feedback, I made a pull request out of this workaround.

If someone wants to use the gem with this fix right now, just use my fork

@fwal
Copy link
Author

fwal commented Jan 11, 2018

Seems abandoned 🗑

@fwal fwal closed this as completed Jan 11, 2018
@ut
Copy link

ut commented Jan 11, 2018

Looking at the queue of the waiting PR, that's a pity.

@rvodden rvodden reopened this Jan 13, 2018
@rvodden
Copy link
Contributor

rvodden commented Jan 13, 2018

Myself at @perlun are in the process of resurrecting the project. I don't want this issue to get lost so I'm re-openong. We've not discussed priorities yet, however internationalization is likely to be high.

@ut
Copy link

ut commented Feb 2, 2018

It seems that this issue has been solved in the meantime. I succesfully checked it with the example provided by @fwal

@fwal
Copy link
Author

fwal commented Feb 2, 2018

That's awesome @ut, then I'll close this for real 🎉

@fwal fwal closed this as completed Feb 2, 2018
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

6 participants