aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Fontaine2014-05-01 01:10:51 +0200
committerAdam Vandenberg2014-05-02 19:50:27 -0700
commit74e4fdfce2e7a2b927c259bf9f977dd6e97643c2 (patch)
tree513c455567db2fab6baccd2072baaf25bcaa2070
parent348d0eb05c9d6482d910ccf0bc0817f872059aef (diff)
downloadbrew-74e4fdfce2e7a2b927c259bf9f977dd6e97643c2.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 Homebrew/homebrew#28873. Signed-off-by: Adam Vandenberg <flangy@gmail.com>
-rw-r--r--Library/Homebrew/extend/string.rb2
-rw-r--r--Library/Homebrew/test/test_string.rb8
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