プロジェクト

全般

プロフィール

Vote #73072

完了

Unable to call a macro with a name that contains uppercase letters

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
63
issue_org_id:
12744
author_id:
31186
assigned_to_id:
1
comments:
8
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
56
ステータス-->[Closed]

説明

I recently upgraded from 2.0 to 2.2 and found that some macros stopped working. Those macros have upper-case letters in their name (e.g., EnableLaTeXMath), and it seems to me that Redmine 2.2 only triggers macro names in lower cases.

hypothesis: when looking up macros, Redmine 2.2 converts the macro name to lower case; but when registering the macro, Redmine 2.2 forgets to lower-case the names. So if a macro has upper case letters in the name during registration, it will never be found when it is called...


journals

Hi there,

well on the first sight, this seems to be ok.

Save a new macro:
source:trunk/lib/redmine/wiki_formatting/macros.rb#L153
There is a downcase in line 153

Find the macro:
source:trunk/app/helpers/application_helper.rb#L864
There is a $4.downcase in line 864

--------------------------------------------------------------------------------
I don't know Ruby but this line seems suspicious where name is added to @available_macros@ before downcase: source:trunk/lib/redmine/wiki_formatting/macros.rb#L151

<pre><code class="ruby">
available_macros[name] = {:desc => @@desc || ''}.merge(options)
</code></pre>

(well, it's possible that available_macros is not used during macro look-up. I'll try to figure out why my plugin works only after I rename it to lower-case.)
--------------------------------------------------------------------------------
I think that was the culprit. An ugly line (before that L151) fixes the problem, and confirms that the problem was due to not lower-casing the names during macro registration:

<pre><code class="ruby">
name = "#{name}".downcase # <-- this is the ugly fix
name = name.to_sym if name.is_a?(String)
available_macros[name] = {:desc => @@desc || ''}.merge(options)
@@desc = nil
Definitions.send :define_method, "macro_#{name}", &block # <-- downcase was already done
</code></pre>
--------------------------------------------------------------------------------
Fix committed with test in r11126, thanks for pointing this out.
Maybe we should even make macro name case-sensitive?
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
I can confirm that r11126 fixes the problem. Thanks.
--------------------------------------------------------------------------------
Jean-Philippe Lang wrote:
> Fix committed with test in r11126, thanks for pointing this out.
> Maybe we should even make macro name case-sensitive?

I've just been stuck by this bug with my own macros too. There have already been many macro uses with case-confused names, so I hope they would remain case-insensitive.

Btw, I like !{{macro_list}} to show macro names with case preserved. Please consider a fix like an attached patch.
--------------------------------------------------------------------------------
Merged.

> Btw, I like {{macro_list}} to show macro names with case preserved. Please consider a fix like an attached patch.

Will be fixed as a separate issue.
--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリPlugin API_20 にセット
  • 対象バージョン2.2.1_63 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0