diff --git a/Gemfile b/Gemfile index ced4bbd2dc1..cf250465649 100644 --- a/Gemfile +++ b/Gemfile @@ -67,9 +67,6 @@ gem 'multi_json' gem 'mustache' gem 'nokogiri' -# this may end up deprecating nokogiri -gem 'oga', require: false - gem 'omniauth' gem 'omniauth-openid' gem 'openid-redis-store' diff --git a/Gemfile.lock b/Gemfile.lock index 7029f5d7cee..09d9ff3bb30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,6 @@ GEM annotate (2.7.2) activerecord (>= 3.2, < 6.0) rake (>= 10.4, < 13.0) - ansi (1.5.0) arel (8.0.0) ast (2.3.0) aws-partitions (1.24.0) @@ -200,9 +199,6 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - oga (2.10) - ast - ruby-ll (~> 2.1) oj (3.1.0) omniauth (1.6.1) hashie (>= 3.4.6, < 3.6.0) @@ -334,9 +330,6 @@ GEM rainbow (>= 2.2.2, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - ruby-ll (2.1.2) - ansi - ast ruby-openid (2.7.0) ruby-prof (0.16.2) ruby-progressbar (1.9.0) @@ -459,7 +452,6 @@ DEPENDENCIES multi_json mustache nokogiri - oga oj omniauth omniauth-facebook diff --git a/lib/html_normalize.rb b/lib/html_normalize.rb deleted file mode 100644 index 1243a4426a6..00000000000 --- a/lib/html_normalize.rb +++ /dev/null @@ -1,151 +0,0 @@ -# frozen_string_literal: true -# -# this class is used to normalize html output for internal comparisons in specs -# -require 'oga' - -class HtmlNormalize - - def self.normalize(html) - parsed = Oga.parse_html(html.strip, strict: true) - if parsed.children.length != 1 - puts parsed.children.count - raise "expecting a single child" - end - new(parsed.children.first).format - end - - SELF_CLOSE = Set.new(%w{area base br col command embed hr img input keygen line meta param source track wbr}) - - BLOCK = Set.new(%w{ - html - body - aside - p - h1 h2 h3 h4 h5 h6 - ol ul - address - blockquote - dl - div - fieldset - form - hr - noscript - table - pre - }) - - def initialize(doc) - @doc = doc - end - - def format - buffer = String.new - dump_node(@doc, 0, buffer) - buffer.strip! - buffer - end - - def inline?(node) - Oga::XML::Text === node || !BLOCK.include?(node.name.downcase) - end - - def dump_node(node, indent = 0, buffer) - - if Oga::XML::Text === node - if node.parent&.name - buffer << node.text - end - return - end - - name = node.name.downcase - - block = BLOCK.include?(name) - - buffer << " " * indent * 2 if block - - buffer << "<" << name - - attrs = node&.attributes - if (attrs && attrs.length > 0) - attrs.sort! { |x, y| x.name <=> y.name } - attrs.each do |a| - buffer << " " - buffer << a.name - if a.value - buffer << "='" - buffer << a.value - buffer << "'" - end - end - end - - buffer << ">" - - if block - buffer << "\n" - end - - children = node.children - children = trim(children) if block - - inline_buffer = nil - - children&.each do |child| - if block && inline?(child) - inline_buffer ||= String.new - dump_node(child, indent + 1, inline_buffer) - else - if inline_buffer - buffer << " " * (indent + 1) * 2 - buffer << inline_buffer.strip - inline_buffer = nil - else - dump_node(child, indent + 1, buffer) - end - end - end - - if inline_buffer - buffer << " " * (indent + 1) * 2 - buffer << inline_buffer.strip - inline_buffer = nil - end - - if block - buffer << "\n" unless buffer[-1] == "\n" - buffer << " " * indent * 2 - end - - unless SELF_CLOSE.include?(name) - buffer << "\n" - end - end - - def trim(nodes) - start = 0 - finish = nodes.length - - nodes.each do |n| - if Oga::XML::Text === n && n.text.blank? - start += 1 - else - break - end - end - - nodes.reverse_each do |n| - if Oga::XML::Text === n && n.text.blank? - finish -= 1 - else - break - end - end - - nodes[start...finish] - end - -end diff --git a/plugins/poll/spec/lib/pretty_text_spec.rb b/plugins/poll/spec/lib/pretty_text_spec.rb index 85ee2c2a00e..fedc70eb986 100644 --- a/plugins/poll/spec/lib/pretty_text_spec.rb +++ b/plugins/poll/spec/lib/pretty_text_spec.rb @@ -1,10 +1,9 @@ require 'rails_helper' -require 'html_normalize' describe PrettyText do def n(html) - HtmlNormalize.normalize(html) + html.strip end it 'supports multi choice polls' do @@ -95,14 +94,13 @@ describe PrettyText do cooked = PrettyText.cook md expected = <<~MD -
+
    -
  1. test 1 :slight_smile: test -
  2. -
  3. test 2
  4. +
  5. test 1 :slight_smile: test
  6. +
  7. test 2
@@ -110,12 +108,9 @@ describe PrettyText do 0 voters

-

- Choose up to 2 options

diff --git a/spec/components/html_normalize_spec.rb b/spec/components/html_normalize_spec.rb deleted file mode 100644 index 7c75d8a15bd..00000000000 --- a/spec/components/html_normalize_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'rails_helper' -require 'html_normalize' - -describe HtmlNormalize do - - def n(html) - HtmlNormalize.normalize(html) - end - - it "handles attributes without values" do - expect(n "").to eq("") - end - - it "handles self closing tags" do - - source = <<-HTML -
- - boo -
-HTML - expect(n source).to eq(source.strip) - end - - it "Can handle aside" do - - source = <<~HTML - -HTML - expected = <<~HTML - -HTML - - expect(n expected).to eq(n source) - end - - it "Can normalize attributes" do - - source = "b" - same = "b" - - expect(n source).to eq(n same) - end - - it "Can indent divs nicely" do - source = "
hello world
" - expected = <<~HTML -
-
-
- hello world -
-
-
-HTML - - expect(n source).to eq(expected.strip) - end -end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 971d7dd6005..487ec569681 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -1,6 +1,5 @@ require 'rails_helper' require 'pretty_text' -require 'html_normalize' describe PrettyText do @@ -9,11 +8,11 @@ describe PrettyText do end def n(html) - HtmlNormalize.normalize(html) + html.strip end def cook(*args) - n(PrettyText.cook(*args)) + PrettyText.cook(*args) end let(:wrapped_image) { "
\nScreen Shot 2014-04-14 at 9.47.10 PM.png966x737 1.47 MB\n
" } @@ -33,13 +32,13 @@ describe PrettyText do topic = Fabricate(:topic, title: "this is a test topic :slight_smile:") expected = <<~HTML -