lib/sprockets/encoding_utils.rb in sprockets-3.0.1 vs lib/sprockets/encoding_utils.rb in sprockets-3.0.2

- old
+ new

@@ -102,11 +102,11 @@ # Attempt Charlock detection if str.encoding == Encoding::BINARY charlock_detect(str) end - # Fallback to UTF-8 + # Fallback to environment's external encoding if str.encoding == Encoding::BINARY str.force_encoding(Encoding.default_external) end str @@ -231,12 +231,15 @@ end nil end - # Public: Detect charset from HTML document. Defaults to ISO-8859-1. + # Public: Detect charset from HTML document. # + # Attempts to parse any Unicode BOM otherwise attempt Charlock detection + # and finally falls back to the environment's external encoding. + # # str - String. # # Returns a encoded String. def detect_html(str) str = detect_unicode_bom(str) @@ -244,12 +247,12 @@ # Attempt Charlock detection if str.encoding == Encoding::BINARY charlock_detect(str) end - # Fallback to ISO-8859-1 + # Fallback to environment's external encoding if str.encoding == Encoding::BINARY - str.force_encoding(Encoding::ISO_8859_1) + str.force_encoding(Encoding.default_external) end str end CHARSET_DETECT[:html] = method(:detect_html)