Permalink
Browse files

Add heredoc_safe method for inserting heredocs

This is used for the "postinstall" action, which can drop custom scripts
onto the node to be run after the node spins up.
  • Loading branch information...
1 parent 869d9c0 commit 5c2d1e0ebf16aa3fa43b60fd79a3aad57c2a3612 @reidmv reidmv committed Oct 31, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/puppet/stack.rb
View
@@ -402,4 +402,25 @@ def self.queue
@queue ||= Queue.new
end
+ def self.heredoc_safe(string)
+ # lifted from shellquote function on 2012/10/22
+ safe = '!"a-zA-Z0-9@%_+=:,./-' # Safe unescaped
+ dangerous = '`$\\' # Unsafe without escape
+
+ if string.length != 0 and string.count(safe) == string.length
+ return string
+ elsif string.count(dangerous) == 0
+ return ('"' + string + '"')
+ elsif string.count("'") == 0
+ return ("'" + string + "'")
+ else
+ r = String.new
+ string.each_byte do |c|
+ r += "\\" if dangerous.include?(c)
+ r += c.chr
+ end
+ return r
+ end
+ end
+
end

0 comments on commit 5c2d1e0

Please sign in to comment.