Project

General

Profile

Bug #15933 ยป ruby-changes-combined.patch

gareth (Gareth Adams), 06/27/2019 05:42 PM

View differences:

lib/open-uri.rb
543 543
    # It can be used to guess charset.
544 544
    #
545 545
    # If charset parameter and block is not given,
546
    # nil is returned except text type in HTTP.
547
    # In that case, "iso-8859-1" is returned as defined by RFC2616 3.7.1.
546
    # nil is returned except text type.
547
    # In that case, "utf-8" is returned as defined by RFC6838 4.2.1
548 548
    def charset
549 549
      type, *parameters = content_type_parse
550 550
      if pair = parameters.assoc('charset')
551 551
        pair.last.downcase
552 552
      elsif block_given?
553 553
        yield
554
      elsif type && %r{\Atext/} =~ type &&
555
            @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
556
        "iso-8859-1" # RFC2616 3.7.1
554
      elsif type && %r{\Atext/} =~ type
555
        "utf-8" # RFC6838 4.2.1
557 556
      else
558 557
        nil
559 558
      end