Skip to content

Commit

Permalink
handle commit messages with quotation marks
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Dec 29, 2012
1 parent 2596f7c commit 62efef5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- this should also result in less problems with IM version changes
- some preliminary test work on using image_sorcery instead too
- perhaps finally kill issue #9 from continually resurfacing
* make sure quotes are properly handled in commit messages

0.3.4 (27 December 2012)
* Add uploldz plugin for posting to a remote server (thx @cnvandev)
Expand Down
5 changes: 5 additions & 0 deletions features/lolcommits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ Feature: Basic UI functionality
Then the output should contain "Can't do that since we're not in a valid git repository!"
And the exit status should be 1

Scenario: handle commit messages with quotation marks
Given I am in a git repository named "shellz" with lolcommits enabled
When I successfully run `git commit --allow-empty -m 'i hate \"air quotes\" dont you'`
Then the exit status should be 0
And there should be exactly 1 jpg in "../.lolcommits/shellz"
14 changes: 13 additions & 1 deletion lib/lolcommits/plugins/loltext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def mm_run
c.pointsize '48'
c.interline_spacing '-9'
c.font font_location
c.annotate '0', word_wrap(self.runner.message)
c.annotate '0', clean_msg(self.runner.message)
end

image.combine_options do |c|
Expand Down Expand Up @@ -68,6 +68,18 @@ def mm_run

private

# do whatever is required to commit message to get it clean and ready for imagemagick
def clean_msg(text)
wrapped_text = word_wrap text
escape_quotes wrapped_text
end

# conversion for quotation marks to avoid shell interpretation
# does not seem to be a safe way to escape cross-platform?
def escape_quotes(text)
text.gsub(/"/, "''")
end

# convenience method for word wrapping
# based on https://github.com/cmdrkeene/memegen/blob/master/lib/meme_generator.rb
def word_wrap(text, col = 27)
Expand Down

0 comments on commit 62efef5

Please sign in to comment.