Skip to content

Commit

Permalink
Changed Psych::Visitors::YAMLTree.binary?(string).
Browse files Browse the repository at this point in the history
* A human-readable representation can be used for ascii_only 8bit-encoded strings.
* String subclasses are binary, even if they are character-encoded.
  • Loading branch information
pck committed Jan 6, 2013
1 parent bdd8e9d commit ef4f041
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/psych/visitors/yaml_tree.rb
Expand Up @@ -221,9 +221,10 @@ def visit_BigDecimal o
end

def binary? string
string.encoding == Encoding::ASCII_8BIT ||
(string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) ||
string.index("\x00") ||
string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3
string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3 ||
string.class != String
end
private :binary?

Expand Down

0 comments on commit ef4f041

Please sign in to comment.