Skip to main content

Module ruby

Module ruby 

Source
Expand description

ruby literal encoder.

encodes untrusted strings for safe embedding in ruby source literals.

§encoding rules

the encoder uses ruby’s native escape syntax:

  • named escapes: \a, \b, \t, \n, \v, \f, \r, \e, \\
  • double quote → \"
  • hash sign → \# (prevents #{}, #$, #@ interpolation)
  • other C0 controls and DEL → \xHH
  • unicode non-characters → space
  • non-ASCII unicode passes through (ruby 2.0+ source files are UTF-8 by default)

the output is safe for double-quoted string literals only. ruby single-quoted strings ('...') use different escape rules and are not covered by this encoder.

Functions§

for_ruby_string
encodes input for safe embedding in a ruby double-quoted string literal ("...").
write_ruby_string
writes the ruby-string-encoded form of input to out.