https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292013-01-05T11:20:12ZRedmineRedmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=437992013-01-05T11:20:12ZDaniel Felix
<ul></ul><p>Hi there,</p>
<p>well on the first sight, this seems to be ok.</p>
<p>Save a new macro:<br /><a class="source" href="https://www.redmine.org/projects/redmine/repository/svn/entry/trunk/lib/redmine/wiki_formatting/macros.rb#L153">source:trunk/lib/redmine/wiki_formatting/macros.rb#L153</a> <br />There is a downcase in line 153</p>
<p>Find the macro:<br /><a class="source" href="https://www.redmine.org/projects/redmine/repository/svn/entry/trunk/app/helpers/application_helper.rb#L864">source:trunk/app/helpers/application_helper.rb#L864</a><br />There is a $4.downcase in line 864</p> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438422013-01-05T20:39:33ZLing Li
<ul></ul><p>I don't know Ruby but this line seems suspicious where name is added to <code>available_macros</code> before downcase: <a class="source" href="https://www.redmine.org/projects/redmine/repository/svn/entry/trunk/lib/redmine/wiki_formatting/macros.rb#L151">source:trunk/lib/redmine/wiki_formatting/macros.rb#L151</a></p>
<pre><code class="ruby syntaxhl"><span class="n">available_macros</span><span class="p">[</span><span class="nb">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="ss">:desc</span> <span class="o">=></span> <span class="vc">@@desc</span> <span class="o">||</span> <span class="s1">''</span><span class="p">}.</span><span class="nf">merge</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
</code></pre>
<p>(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.)</p> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438432013-01-05T20:54:48ZLing Li
<ul></ul><p>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:</p>
<pre><code class="ruby syntaxhl"> <span class="nb">name</span> <span class="o">=</span> <span class="s2">"</span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span><span class="p">.</span><span class="nf">downcase</span> <span class="c1"># <-- this is the ugly fix</span>
<span class="nb">name</span> <span class="o">=</span> <span class="nb">name</span><span class="p">.</span><span class="nf">to_sym</span> <span class="k">if</span> <span class="nb">name</span><span class="p">.</span><span class="nf">is_a?</span><span class="p">(</span><span class="no">String</span><span class="p">)</span>
<span class="n">available_macros</span><span class="p">[</span><span class="nb">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="ss">:desc</span> <span class="o">=></span> <span class="vc">@@desc</span> <span class="o">||</span> <span class="s1">''</span><span class="p">}.</span><span class="nf">merge</span><span class="p">(</span><span class="n">options</span><span class="p">)</span>
<span class="vc">@@desc</span> <span class="o">=</span> <span class="kp">nil</span>
<span class="no">Definitions</span><span class="p">.</span><span class="nf">send</span> <span class="ss">:define_method</span><span class="p">,</span> <span class="s2">"macro_</span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span><span class="p">,</span> <span class="o">&</span><span class="n">block</span> <span class="c1"># <-- downcase was already done</span>
</code></pre> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438452013-01-05T23:13:16ZJean-Philippe Langjp_lang@yahoo.fr
<ul><li><strong>Subject</strong> changed from <i>Macro name has to be lower-cased?</i> to <i>Unable to call a macro with a name that contains uppercase letters</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li><li><strong>Assignee</strong> set to <i>Jean-Philippe Lang</i></li><li><strong>Target version</strong> set to <i>2.2.1</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Fix committed with test in <a class="changeset" title="Fixed that macros with uppercase letters can not be called (#12744)." href="https://www.redmine.org/projects/redmine/repository/svn/revisions/11126">r11126</a>, thanks for pointing this out.<br />Maybe we should even make macro name case-sensitive?</p> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438462013-01-05T23:13:23ZJean-Philippe Langjp_lang@yahoo.fr
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Resolved</i></li></ul> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438482013-01-06T01:28:43ZLing Li
<ul></ul><p>I can confirm that <a class="changeset" title="Fixed that macros with uppercase letters can not be called (#12744)." href="https://www.redmine.org/projects/redmine/repository/svn/revisions/11126">r11126</a> fixes the problem. Thanks.</p> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=438782013-01-06T18:22:45ZTakeshi Yaegashi
<ul><li><strong>File</strong> <a href="/attachments/8743">0001-Preserve-case-of-macro-names-shown-by-macro_list.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/8743/0001-Preserve-case-of-macro-names-shown-by-macro_list.patch">0001-Preserve-case-of-macro-names-shown-by-macro_list.patch</a> added</li></ul><p>Jean-Philippe Lang wrote:</p>
<blockquote>
<p>Fix committed with test in <a class="changeset" title="Fixed that macros with uppercase letters can not be called (#12744)." href="https://www.redmine.org/projects/redmine/repository/svn/revisions/11126">r11126</a>, thanks for pointing this out.<br />Maybe we should even make macro name case-sensitive?</p>
</blockquote>
<p>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.</p>
<p>Btw, I like {{macro_list}} to show macro names with case preserved. Please consider a fix like an attached patch.</p> Redmine - Defect #12744: Unable to call a macro with a name that contains uppercase lettershttps://www.redmine.org/issues/12744?journal_id=440042013-01-09T13:31:32ZJean-Philippe Langjp_lang@yahoo.fr
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li></ul><p>Merged.</p>
<blockquote>
<p>Btw, I like <dl><dt><code>hello_world</code></dt><dd><pre>Sample macro.</pre></dd><dt><code>macro_list</code></dt><dd><pre>Displays a list of all available macros, including description if available.</pre></dd><dt><code>child_pages</code></dt><dd><pre>Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:
{{child_pages}} -- can be used from a wiki page only
{{child_pages(depth=2)}} -- display 2 levels nesting only
{{child_pages(Foo)}} -- lists all children of page Foo
{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo</pre></dd><dt><code>include</code></dt><dd><pre>Includes a wiki page. Examples:
{{include(Foo)}}
{{include(projectname:Foo)}} -- to include a page of a specific project wiki</pre></dd><dt><code>collapse</code></dt><dd><pre>Inserts of collapsed block of text. Examples:
{{collapse
This is a block of text that is collapsed by default.
It can be expanded by clicking a link.
}}
{{collapse(View details...)
With custom link text.
}}</pre></dd><dt><code>thumbnail</code></dt><dd><pre>Displays a clickable thumbnail of an attached image.
Default size is 200 pixels. Examples:
{{thumbnail(image.png)}}
{{thumbnail(image.png, size=300, title=Thumbnail)}} -- with custom title and size</pre></dd><dt><code>issue</code></dt><dd><pre>Displays an issue link including additional information. Examples:
{{issue(123)}} -- Issue #123: Enhance macro capabilities
{{issue(123, project=true)}} -- Andromeda - Issue #123: Enhance macro capabilities
{{issue(123, tracker=false)}} -- #123: Enhance macro capabilities
{{issue(123, subject=false, project=true)}} -- Andromeda - Issue #123
</pre></dd><dt><code>sample_macro</code></dt><dd><pre>Sample macro</pre></dd></dl> to show macro names with case preserved. Please consider a fix like an attached patch.</p>
</blockquote>
<p>Will be fixed as a separate issue.</p>