]> cat aescling's git repositories - mastodon.git/commitdiff
Merge branch 'master' into glitch-soc/merge-upstream
authorThibaut Girka <thib@sitedethib.com>
Sun, 9 Feb 2020 11:15:55 +0000 (12:15 +0100)
committerThibaut Girka <thib@sitedethib.com>
Sun, 9 Feb 2020 11:15:55 +0000 (12:15 +0100)
Conflicts:
- `Gemfile`:
  We updated httplog in a separate commit.
  Took upstream's change which updated it further.
- `Gemfile.lock`:
  We updated httplog in a separate commit.
  Took upstream's change which updated it further.
- `app/lib/sanitize_config.rb`:
  Upstream added better unsupported link stripping,
  while we had different sanitizing configs.
  Took only upstream's link stripping code.
- `config/locales/simple_form.pl.yml`:
  Strings unused in glitch-soc had been removed from
  glitch-soc, reintroduced them even if they are not
  useful, to reduce the risk of later merge conflicts.

1  2 
Gemfile
Gemfile.lock
app/controllers/tags_controller.rb
app/javascript/mastodon/locales/pl.json
app/javascript/styles/mastodon/components.scss
app/lib/formatter.rb
app/lib/sanitize_config.rb
config/locales/pl.yml
config/locales/simple_form.pl.yml
lib/mastodon/version.rb
spec/lib/sanitize_config_spec.rb

diff --cc Gemfile
Simple merge
diff --cc Gemfile.lock
Simple merge
Simple merge
index f1a751f84b37be851a72313450971d36f42843e6,e6f5d7a6327969a990f12bab33ff0e26dc79530d..fcc99d0095baf273fb2c770ac72d434449492e43
@@@ -70,13 -44,10 +70,15 @@@ class Formatte
      html.html_safe # rubocop:disable Rails/OutputSafety
    end
  
 +  def format_markdown(html)
 +    html = markdown_formatter.render(html)
 +    html.delete("\r").delete("\n")
 +  end
 +
    def reformat(html)
      sanitize(html, Sanitize::Config::MASTODON_STRICT)
+   rescue ArgumentError
+     ''
    end
  
    def plaintext(status)
index 2b5d554b5a6dccf63340b9e2fefc510e75986f7b,4ad1199a60442c9788d8c731e963ff31cfd1a62b..e3fc94ba637a7600c4d315f3c5d4c9587ccf7534
@@@ -19,33 -35,46 +35,49 @@@ class Sanitiz
        node['class'] = class_list.join(' ')
      end
  
 -    UNSUPPORTED_ELEMENTS_TRANSFORMER = lambda do |env|
 -      return unless %w(h1 h2 h3 h4 h5 h6 blockquote pre ul ol li).include?(env[:node_name])
 -
 -      current_node = env[:node]
 -
 -      case env[:node_name]
 -      when 'li'
 -        current_node.traverse do |node|
 -          next unless %w(p ul ol li).include?(node.name)
 -
 -          node.add_next_sibling('<br>') if node.next_sibling
 -          node.replace(node.children) unless node.text?
 -        end
 -      else
 -        current_node.name = 'p'
 -      end
 -    end
 -
 +    IMG_TAG_TRANSFORMER = lambda do |env|
 +      node = env[:node]
 +
 +      return unless env[:node_name] == 'img'
 +
 +      node.name = 'a'
 +
 +      node['href'] = node['src']
 +      if node['alt'].present?
 +        node.content = "[🖼  #{node['alt']}]"
 +      else
 +        url = node['href']
 +        prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
 +        text   = url[prefix.length, 30]
 +        text   = text + "…" if url[prefix.length..-1].length > 30
 +        node.content = "[🖼  #{text}]"
 +      end
 +    end
 +
+     UNSUPPORTED_HREF_TRANSFORMER = lambda do |env|
+       return unless env[:node_name] == 'a'
+       current_node = env[:node]
+       scheme = begin
+         if current_node['href'] =~ Sanitize::REGEX_PROTOCOL
+           Regexp.last_match(1).downcase
+         else
+           :relative
+         end
+       end
+       current_node.replace(current_node.text) unless LINK_PROTOCOLS.include?(scheme)
+     end
      MASTODON_STRICT ||= freeze_config(
 -      elements: %w(p br span a),
 +      elements: %w(p br span a abbr del pre blockquote code b strong u sub sup i em h1 h2 h3 h4 h5 ul ol li),
  
        attributes: {
 -        'a'    => %w(href rel class),
 -        'span' => %w(class),
 +        'a'          => %w(href rel class title),
 +        'span'       => %w(class),
 +        'abbr'       => %w(title),
 +        'blockquote' => %w(cite),
        },
  
        add_attributes: {
          },
        },
  
 -      protocols: {},
 +      protocols: {
-         'a'          => { 'href' => HTTP_PROTOCOLS },
-         'blockquote' => { 'cite' => HTTP_PROTOCOLS },
++        'a'          => { 'href' => LINK_PROTOCOLS },
++        'blockquote' => { 'cite' => LINK_PROTOCOLS },
 +      },
  
        transformers: [
          CLASS_WHITELIST_TRANSFORMER,
 -        UNSUPPORTED_ELEMENTS_TRANSFORMER,
 +        IMG_TAG_TRANSFORMER,
+         UNSUPPORTED_HREF_TRANSFORMER,
        ]
      )
  
Simple merge
index d3d726440d9fdd965007cc4298b51e9b137b5d49,e8e2251b0dde40730c019840084f4553b23663e8..c985badb40e2ab737f28aedacd472f57e7eb406e
@@@ -108,10 -122,12 +124,13 @@@ pl
          setting_noindex: Nie indeksuj mojego profilu w wyszukiwarkach internetowych
          setting_reduce_motion: Ogranicz ruch w animacjach
          setting_show_application: Informuj o aplikacji z której wysłano wpisy
 +        setting_skin: Motyw
          setting_system_font_ui: Używaj domyślnej czcionki systemu
+         setting_theme: Motyw strony
+         setting_trends: Pokazuj dzisiejsze „Na czasie”
          setting_unfollow_modal: Pytaj o potwierdzenie przed cofnięciem śledzenia
          setting_use_blurhash: Pokazuj kolorowe gradienty dla ukrytej zawartości multimedialnej
+         setting_use_pending_items: Tryb spowolniony
          severity: Priorytet
          type: Importowane dane
          username: Nazwa użytkownika
Simple merge
index c5143bcefa73d875e102bf9928ed8bdf4aaba27a,d66302e6449eca185bb399cd8f89e7bb4e2dd48e..0a812e8726951029c4618f7830d8704f3bf056c5
@@@ -7,12 -7,40 +7,28 @@@ describe Sanitize::Config d
    describe '::MASTODON_STRICT' do
      subject { Sanitize::Config::MASTODON_STRICT }
  
 -    it 'converts h1 to p' do
 -      expect(Sanitize.fragment('<h1>Foo</h1>', subject)).to eq '<p>Foo</p>'
 +    it 'keeps h1' do
 +      expect(Sanitize.fragment('<h1>Foo</h1>', subject)).to eq '<h1>Foo</h1>'
      end
  
 -    it 'converts ul to p' do
 -      expect(Sanitize.fragment('<p>Check out:</p><ul><li>Foo</li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p>Foo<br>Bar</p>'
 -    end
 -
 -    it 'converts p inside ul' do
 -      expect(Sanitize.fragment('<ul><li><p>Foo</p><p>Bar</p></li><li>Baz</li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
 -    end
 -
 -    it 'converts ul inside ul' do
 -      expect(Sanitize.fragment('<ul><li>Foo</li><li><ul><li>Bar</li><li>Baz</li></ul></li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
 -    end
 -
 -    it 'keep links in lists' do
 -      expect(Sanitize.fragment('<p>Check out:</p><ul><li><a href="https://joinmastodon.org" rel="nofollow noopener noreferrer" target="_blank">joinmastodon.org</a></li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p><a href="https://joinmastodon.org" rel="nofollow noopener noreferrer" target="_blank">joinmastodon.org</a><br>Bar</p>'
 +    it 'keeps ul' do
 +      expect(Sanitize.fragment('<p>Check out:</p><ul><li>Foo</li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><ul><li>Foo</li><li>Bar</li></ul>'
      end
+     it 'removes a without href' do
+       expect(Sanitize.fragment('<a>Test</a>', subject)).to eq 'Test'
+     end
+     it 'removes a without href and only keeps text content' do
+       expect(Sanitize.fragment('<a><span class="invisible">foo&amp;</span><span>Test</span></a>', subject)).to eq 'foo&amp;Test'
+     end
+     it 'removes a with unsupported scheme in href' do
+       expect(Sanitize.fragment('<a href="foo://bar">Test</a>', subject)).to eq 'Test'
+     end
+     it 'keeps a with href' do
+       expect(Sanitize.fragment('<a href="http://example.com">Test</a>', subject)).to eq '<a href="http://example.com" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
+     end
    end
  end