Project

General

Profile

Actions

Defect #42648

open

Wiki/CommonMark: Broken references for multiple footnote usage

Added by Luc Luc 2 days ago. Updated about 7 hours ago.

Status:
Resolved
Priority:
Normal
Category:
Text formatting
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Wiki/CommonMark: Broken references for multiple footnote usage

Description

When using the same footnote more than once with CommonMark wiki flavor, all references except the first one are broken due to the sanitization filter.

Affected version: 6.0.5.

How to reproduce

1. Use CommonMark for wiki pages
2. Create a simple wiki page containing the same footnote at least two times

This is the first usage of a footnote[^1].
Use the same footnote[^1] a second time.

[^1]: A note placed at the bottom of a page that comments on or cites a reference for a designated part of the text.


3. Observe the first back-reference is working as expected by jumping back to the first footnote usage (see #fnref-1)
4. Observe the second back-reference does not work, it doesn't jump back to the second footnote usage (see #fnref-1-2).

Proposed fix

diff --git a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
index cdefc372b..459610354 100644
--- a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
+++ b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
@@ -86,8 +86,8 @@ module Redmine
             node = env[:node]
             return unless node.name == "a" || node.name == "li" 
             return unless node.has_attribute?("id")
-            return if node.name == "a" && node["id"] =~ /\Afnref-\d+\z/
-            return if node.name == "li" && node["id"] =~ /\Afn-\d+\z/
+            return if node.name == "a" && node["id"] =~ /\Afnref(-\d+){1,2}\z/
+            return if node.name == "li" && node["id"] =~ /\Afn(-\d+){1,2}\z/

             node.remove_attribute("id")
           }

Files

Actions #1

Updated by Marius BĂLTEANU 1 day ago

  • Category changed from Wiki to Text formatting
  • Status changed from New to Confirmed
  • Assignee set to Marius BĂLTEANU
  • Target version set to 5.1.9
Actions #2

Updated by Marius BĂLTEANU 1 day ago

Thanks for reporting the issue and the fix.

I'm not sure why the below change is required:

- return if node.name == "li" && node["id"] =~ /\Afn-\d+\z/
+ return if node.name == "li" && node["id"] =~ /\Afn(-\d+){1,2}\z/

li tags with id fn-* are used in the footnotes section and they should not have multiple occurrence of the same footnote.

Can you help me reproduce this change?

Actions #3

Updated by Luc Luc about 16 hours ago

Hello Marius,

thanks for looking into it.

I'm not sure why the below change is required:
[...]
li tags with id fn-* are used in the footnotes section and they should not have multiple occurrence of the same footnote.

You're absolutely right, the second change is obviously not required.
It looks like I've been affected by the "copy/paste syndrome", also having close to nothing experience with redmine source code helped a bit.

Can you help me reproduce this change?

Sure, just let me know if you think of something specific.
I already tested 6.0.5 + the patch changed as per your suggestion (attached to this note) and it works as expected.

Thank's again.

Actions #4

Updated by Marius BĂLTEANU about 7 hours ago

  • Status changed from Confirmed to Resolved
  • Resolution set to Fixed

Luc Luc wrote in #note-3:

Hello Marius,

thanks for looking into it.

I'm not sure why the below change is required:
[...]
li tags with id fn-* are used in the footnotes section and they should not have multiple occurrence of the same footnote.

You're absolutely right, the second change is obviously not required.
It looks like I've been affected by the "copy/paste syndrome", also having close to nothing experience with redmine source code helped a bit.

Don't worry, I wanted to double check with you. I've committed the fix, it will be available in the next minor releases.

Actions

Also available in: Atom PDF