Sha256: a36e81fbdc30d1d43e752a6076c436ab8cfe5877fb6f0f4c9aac2a0db9a619ef
Contents?: true
Size: 1.57 KB
Versions: 18
Compression:
Stored size: 1.57 KB
Contents
require 'Shellwords' # Escaping parameters module Escape # Escaping floats module FloatEscape def javascript_argument to_s end end # Escaping integers module IntegerEscape def javascript_argument to_s end end # Escaping strings module StringEscape def javascript_argument "'#{StringEscape.javascript_escape(self)}'" end def javascript_escape StringEscape.javascript_escape(self) end def javascript_escape! replace(StringEscape.javascript_escape(self)) end def float? true if Float(self) rescue StandardError false end def integer? to_i.to_s == self end def shell_escape StringEscape.shell_escape(self) end def shell_escape! replace(StringEscape.shell_escape(self)) end # TODO: `self.javascript_escape` and `self.shell_escape` should be private, # but instance methods can't call private class methods in Ruby? Or can # they this only fails when the code imported into the `gem`? def self.javascript_escape(string) # string.gsub('\\', '\\\\\\\\').gsub("\n", '\\\\n').gsub("'", "\\\\'") # Combined as one command, comparable in speed: string.gsub(/\\\\|\n|'/, '\\\\' => '\\\\\\\\', "\n" => '\\n', "'" => '\\\'') end def self.shell_escape(string) Shellwords.escape(string) end end refine String do include StringEscape end refine Integer do include IntegerEscape end refine Float do include FloatEscape end end
Version data entries
18 entries across 18 versions & 1 rubygems