alphanodes / additionals

Redmine plugin for easy customization of settings, text and content display by using personal or role-based dashboards (drag&drop), providing wiki macros and act as library for other plugins.
https://www.redmine.org/plugins/additionals
GNU General Public License v2.0
131 stars 43 forks source link

An error when trying to past emoji when using CommonMark #144

Closed dmakurin closed 2 years ago

dmakurin commented 2 years ago

There is an error when trying to past text containing emoji and redmine formatter is a CommonMark Markdown.

I'm not sure if this is a typo but patch doesn't work for CommonMark. It raises undefined local variable or method 'name'.

Tried on textile - works fine.

dmakurin commented 2 years ago
Environment:
  Redmine version                5.0.2.stable
  Ruby version                   2.7.6-p219 (2022-04-12) [x86_64-linux]
  Rails version                  6.1.6.1
  Environment                    development
  Database adapter               SQLite
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
Redmine settings:
  Redmine theme                  Default
SCM:
  Git                            2.30.2
  Filesystem                     
Redmine plugins:
  additional_tags                1.0.5
  additionals                    3.0.7-main

Steps to reproduce on a fresh setup and loaded fixtures:

  1. Switch to CommonMark in settings => Administration - Settings - General - Text formatting
  2. Enable checkbox Administration - Settings - Additionals - General - Emoji support
  3. Open any issue (/issues/1 eg) and click Edit button
  4. Copy paste: 😀 and click preview

Backtrace:

Completed 500 Internal Server Error in 38ms (ActiveRecord: 9.6ms | Allocations: 9847)

ActionView::Template::Error (undefined local variable or method `name' for #<Additionals::WikiFormatting::CommonMark::EmojiFilter:0x00007fe31e816d80>):
    1: <% unless @text.blank? %>
    2:   <%= textilizable @text, :attachments => @attachments, :object => @previewed %>
    3: <% else  %>
    4:   <p class="empty-preview"><%= l(:label_nothing_to_preview) %></p>
    5: <% end %>

plugins/additionals/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb:48:in `block in emoji_unicode_element_unicode_filter'
plugins/additionals/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb:46:in `gsub'
plugins/additionals/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb:46:in `emoji_unicode_element_unicode_filter'
plugins/additionals/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb:17:in `block in call'
plugins/additionals/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb:12:in `call'
plugins/additionals/lib/additionals/patches/formatter_common_mark_patch.rb:21:in `to_html'
lib/redmine/wiki_formatting.rb:96:in `to_html'
app/helpers/application_helper.rb:869:in `textilizable'
app/views/common/_preview.html.erb:2
app/controllers/previews_controller.rb:30:in `issue'
lib/redmine/sudo_mode.rb:61:in `sudo_mode'
alexandermeindl commented 2 years ago

Hi @dmakurin,

thanks for pointing this out and providing your patch! I used your change for my change and made some cleanups, too.

It should work now with common mark.