From 2fee4ee7f360348774480afa5d2266c9796c3ed4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 27 Nov 2020 08:32:18 +1100 Subject: [PATCH] FIX: bump nokogumbo to 2.0.3 with patch (#11357) PR lodged to nokogumbo so later we should be able to drop freedom patch - https://github.com/rubys/nokogumbo/pull/158 --- Gemfile.lock | 2 +- lib/freedom_patches/nokogumbo.rb | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/freedom_patches/nokogumbo.rb diff --git a/Gemfile.lock b/Gemfile.lock index 88793a0a5fc..037677b9ec6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -204,7 +204,7 @@ GEM nio4r (2.5.4) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - nokogumbo (2.0.2) + nokogumbo (2.0.3) nokogiri (~> 1.8, >= 1.8.4) oauth (0.5.4) oauth2 (1.4.4) diff --git a/lib/freedom_patches/nokogumbo.rb b/lib/freedom_patches/nokogumbo.rb new file mode 100644 index 00000000000..3d0e84853c7 --- /dev/null +++ b/lib/freedom_patches/nokogumbo.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# TODO: Remove once fix is merged and nokogumbo version is bumped +# https://github.com/rubys/nokogumbo/pull/158 + +module Nokogiri + module HTML5 + private + + def self.read_and_encode(string, encoding) + # Read the string with the given encoding. + if string.respond_to?(:read) + if encoding.nil? + string = string.read + else + string = string.read(encoding: encoding) + end + else + # Otherwise the string has the given encoding. + string = string.to_s + if encoding + string = string.dup + string.force_encoding(encoding) + end + end + + # convert to UTF-8 + if string.encoding != Encoding::UTF_8 + string = reencode(string) + end + string + end + end +end