diff options
| -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 |
