diff options
| author | Baptiste Fontaine | 2014-05-01 01:10:51 +0200 | 
|---|---|---|
| committer | Adam Vandenberg | 2014-05-02 19:50:27 -0700 | 
| commit | b3f664c79ffc91080f3b92639ff47f7659ce76d2 (patch) | |
| tree | f24f2a1d17a16a077171f1bea4beda7af9bf958b | |
| parent | 0070c12a9843f9d227473d5b219dc31ad92bfe88 (diff) | |
| download | homebrew-b3f664c79ffc91080f3b92639ff47f7659ce76d2.tar.bz2 | |
Fix for String#undent
Without it, String#undent would fail on unindented strings, e.g.:
    "foo".undent
NoMethodError: undefined method `length' for nil:NilClass`
Closes #28873.
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
| -rw-r--r-- | Library/Homebrew/extend/string.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_string.rb | 8 | 
2 files changed, 9 insertions, 1 deletions
| diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 56126e247..c0f5ae1db 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -1,6 +1,6 @@  class String    def undent -    gsub(/^.{#{slice(/^ +/).length}}/, '') +    gsub(/^.{#{(slice(/^ +/) || '').length}}/, '')    end    # eg: diff --git a/Library/Homebrew/test/test_string.rb b/Library/Homebrew/test/test_string.rb index 6f8692367..547e99c3d 100644 --- a/Library/Homebrew/test/test_string.rb +++ b/Library/Homebrew/test/test_string.rb @@ -10,4 +10,12 @@ class StringTest < Test::Unit::TestCase      EOS      assert undented == "hi\nmy friend over\nthere\n"    end + +  def test_undent_not_indented +    undented = <<-EOS.undent +hi +I'm not indented +    EOS +    assert undented == "hi\nI'm not indented\n" +  end  end | 
