8.7.0 RC1 seemingly broke Markdown rendering
See https://gitlab.com/gitlab-org/gitlab-ce/issues/14935 for an example. Markdown such as # 31st
becomes something like this:
<h1>
<a href="/gitlab-org/gitlab-ce/issues/31" data-original="" data-project="13083" data-issue="14522" data-reference-filter="IssueReferenceFilter" title="Issue: Wiki page internal page links do not work" class="gfm gfm-issue"></a>st31st</h1>
Designs
- Show closed items
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- yorickpeterse-staging mentioned in issue gitlab-com/operations#42 (closed)
mentioned in issue gitlab-com/operations#42 (closed)
- yorickpeterse-staging Reassigned to @rspeicher
Reassigned to @rspeicher
- Owner
Confirmed this was introduced by https://gitlab.com/gitlab-org/gitlab-ce/commit/141148057703048f5c409c040c80c277f7747273, checking into it a bit more.
- Owner
Markdown headers get auto-generated anchor links from
TableOfContentsFilter
. For our monthly release post, one of those anchors might look like this:#31st-16-working-days-before-the-22nd
.Here in
AbstractReferenceFilter
, we're checking iflink =~ /\A#{ref_pattern}/
, which is truthy in these cases.@yorickpeterse Can the fix really be this simple?
diff --git a/lib/banzai/filter/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb index f21dbef..007113a 100644 --- a/lib/banzai/filter/abstract_reference_filter.rb +++ b/lib/banzai/filter/abstract_reference_filter.rb @@ -119,7 +119,7 @@ module Banzai elsif element_node?(node) yield_valid_link(node) do |link, text| - if ref_pattern && link =~ /\A#{ref_pattern}/ + if ref_pattern && text =~ /\A#{ref_pattern}/ replace_link_node_with_href(node, link) do object_link_filter(link, ref_pattern, link_text: text) end
Will leave to you to verify.
- Robert Speicher Reassigned to @yorickpeterse
Reassigned to @yorickpeterse
- Author Maintainer
It appears this problem has existed in some shape or form before. For example, this script:
Rails.cache.clear filters = [ Banzai::Filter::MarkdownFilter, Banzai::Filter::TableOfContentsFilter, Banzai::Filter::AutolinkFilter, Banzai::Filter::IssueReferenceFilter ] project = Project.find_with_namespace('gitlab-org/gitlab-ce') pipeline = HTML::Pipeline.new(filters, project: project) input = "### #{project.issues.first.iid}" document = pipeline.to_document(input) puts 'Partial pipeline:' puts puts document puts puts 'Full pipeline:' puts puts Banzai::Renderer.cacheless_render(input, project: project)
Spits out (both when using 8-6-stable and master):
Partial pipeline: <h3> <a href="http://localhost:3000/gitlab-org/gitlab-ce/issues/2875" data-original="" data-project="13083" data-issue="566948" data-reference-filter="IssueReferenceFilter" title="Issue: Branch labels incorrect in me rge request creation form w/ 8.0.2" class="gfm gfm-issue"></a>2875</h3> Full pipeline: <h3> <a href="/gitlab-org/gitlab-ce/issues/2875" data-original="" data-project="13083" data-issue="566948" data-reference-filter="IssueReferenceFilter" title="Issue: Branch labels incorrect in merge request creation form w/ 8.0.2" class="gfm gfm-issue"></a>2875</h3>
However, the particular problem with
31st
and such appears to indeed be caused by my refactoring. If we change the script to the following:Rails.cache.clear filters = [ Banzai::Filter::MarkdownFilter, Banzai::Filter::TableOfContentsFilter, Banzai::Filter::AutolinkFilter, Banzai::Filter::IssueReferenceFilter ] project = Project.find_with_namespace('gitlab-org/gitlab-ce') pipeline = HTML::Pipeline.new(filters, project: project) input = "### #{project.issues.first.iid}st" document = pipeline.to_document(input) puts 'Partial pipeline:' puts puts document puts puts 'Full pipeline:' puts puts Banzai::Renderer.cacheless_render(input, project: project)
We get this output on 8.6:
Partial pipeline: <h3> <a id="2875st" class="anchor" href="#2875st" aria-hidden="true"></a>2875st</h3> Full pipeline: <h3> <a id="2875st" class="anchor" href="#2875st" aria-hidden="true"></a>2875st</h3>
But on the current master branch we get this instead:
Partial pipeline: <h3> <a href="http://localhost:3000/gitlab-org/gitlab-ce/issues/2875" data-original="" data-project="13083" data-issue="566948" data-reference-filter="IssueReferenceFilter" title="Issue: Branch labels incorrect in merge request creation form w/ 8.0.2" class="gfm gfm-issue"></a>st2875st</h3> Full pipeline: <h3> <a href="/gitlab-org/gitlab-ce/issues/2875" data-original="" data-project="13083" data-issue="566948" data-reference-filter="IssueReferenceFilter" title="Issue: Branch labels incorrect in merge request creation form w/ 8.0.2" class="gfm gfm-issue"></a>st2875st</h3>
The suggestion of @rspeicher does solve this particular case but breaks a bunch of other tests. Looking back at the old code this also isn't correct as the old code used to compare the link URL and not the link text.
Edited by yorickpeterse-staging - Author Maintainer
OK so there are two problems:
-
### 1st
gets turned into a link pointing to issue 1, this can be fixed by usingif ref_pattern && link =~ /\A#{ref_pattern}\z/
which is actually the old regex (I forgot to port over the\z
part) -
### 1
gets turned into an issue link, this seems to have always been the case
@rspeicher @DouweM Is it correct that
# 1
gets turned into an issue link? I'd expect this to only happen when using#1
. -
- yorickpeterse-staging mentioned in commit 507cbca3
mentioned in commit 507cbca3
- yorickpeterse-staging mentioned in merge request !3568 (merged)
mentioned in merge request !3568 (merged)
- Maintainer
FYI I reported this in #14930 (closed) (I will close it since you started digging the issue here).
- username-removed-128633 mentioned in issue #14939 (closed)
mentioned in issue #14939 (closed)
- username-removed-128633 Added regression label
Added regression label
- username-removed-128633 mentioned in issue #14930 (closed)
mentioned in issue #14930 (closed)
- Owner
Is it correct that
# 1
gets turned into an issue link? I'd expect this to only happen when using#1
.@yorickpeterse No, it should never match on the version with a space.
I'm surprised you're having trouble recreating it in a test. Make sure that:
- You pass through both
MarkdownFilter
to convert the headers, thenTableOfContentsFilter
to add anchor links to the headers - Whatever number you put in the header (e.g.,
### 31st
) needs to have an issue with that sameiid
(i.e., 31).
Edited by Robert Speicher - You pass through both
- Douwe Maan mentioned in commit fe132f52
mentioned in commit fe132f52
- Author Maintainer
The initial problem got fixed in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3568, next I'll take a look at
# 1
getting turned into issue references. - Author Maintainer
The problem with
# 1
getting turned into a reference link is as follows:-
# 1
gets turned into a header for the TOC, something like<h1> <a id="1" class="anchor" href="#1" aria-hidden="true"></a>1</h1>
- The IssueReferenceFilter processes this link and runs
if ref_pattern && link =~ /\A#{ref_pattern}\z/
(AbstractReferenceFilter line 122) which returns0
- The following code processes this as if it were an issue reference
I'm not entirely sure just yet what the best way of fixing this would be. @rspeicher @DouweM: any thoughts?
-
- Author Maintainer
To reproduce this problem I wrote the following test:
diff --git a/spec/lib/banzai/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb index 266ebef..3ef77e8 100644 --- a/spec/lib/banzai/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -103,6 +103,13 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do expect(link).to eq(href) end + + it 'does not process links pointing to issue references' do + input = "# #{issue.iid}" + doc = reference_filter("<a href='#{reference}'>#{issue.iid}</a>") + + expect(document.to_html).to eq(input) + end end context 'cross-project reference' do
- Maintainer
If trying to find references in link hrefs causes issues, ww can remove the functionality, I think. See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3568#note_4633504
The use of that feature was pretty far fetched anyway.
- Author Maintainer
@rspeicher @DouweM (and cc-ing @dzaporozhets so he can also give his opinion): so what's the final verdict, do we keep the feature (leading to the somewhat odd linking behaviour described) or do we ditch it entirely?
- Owner
@yorickpeterse ditch it and fix
# 1
. It should not be a link but h1 - Owner
@yorickpeterse Fine with removing.
- username-removed-128633 Status changed to closed
Status changed to closed
- Maintainer
Fixed by !3568 (merged).
- Author Maintainer
@rymai The issue mentioned above has not yet been fixed so I'll re-open this issue for the time being.
- yorickpeterse-staging Status changed to reopened
Status changed to reopened
- Maintainer
@yorickpeterse Sorry about that! Are you referring to this issue?:
### 1
gets turned into an issue link, this seems to have always been the caseIf yes, I see it fixed, examples: https://gitlab.com/gitlab-org/gitlab-ce/issues/14935 and https://gitlab.com/gitlab-org/gitlab-ce/blob/v8.6.4/doc/update/8.5-to-8.6.md
Btw, the issue was not here before the first 8.7 RC (as reported in https://gitlab.com/gitlab-org/gitlab-ce/issues/14930).
- Author Maintainer
@rymai The problem only occurs when there's nothing following the number. For example, this:
### 1
Gets turned into the following on GitLab.com:
<h3> <a href="/gitlab-org/gitlab-ce/issues/1" data-original="" data-project="13083" data-issue="12379" data-reference-filter="IssueReferenceFilter" title="Issue: GitLab is only useable in English" class="gfm gfm-issue"></a>1</h3>
Here's an example (use Chrome's inspector to see the actual HTML):
1
- Author Maintainer
Oh this is very interesting, it now only happens in the "Preview" tab when writing a comment. The final rendered markdown seems fine. OK...?
- Maintainer
Thanks for the explanation @yorickpeterse, this is subtle! :)
1
2
3
I don't see the issue when previewing my comment, though:
- Author Maintainer
@rymai You can see an example here: http://gfycat.com/MeatyBigheartedKite
- Maintainer
Oh right, this isn't visible since the link has no content. That's why I didn't notice it! Thanks, and sorry for the disturb!
- yorickpeterse-staging Milestone changed to 8.8
Milestone changed to 8.8
- yorickpeterse-staging mentioned in issue #17488 (closed)
mentioned in issue #17488 (closed)
- yorickpeterse-staging Status changed to closed
Status changed to closed
- Author Maintainer
Closing this as the original problem was solved and the header rendering issue is a separate problem as described in #17488 (closed).
- yorickpeterse-staging Mentioned in commit pfjason/gitlab-ce@507cbca3
Mentioned in commit pfjason/gitlab-ce@507cbca3
- Douwe Maan Mentioned in commit pfjason/gitlab-ce@fe132f52
Mentioned in commit pfjason/gitlab-ce@fe132f52
- Douwe Maan mentioned in commit test-nick/gitlab-ce@d0b9bdc0
mentioned in commit test-nick/gitlab-ce@d0b9bdc0
- yorickpeterse-staging mentioned in commit test-nick/gitlab-ce@51d18ed4
mentioned in commit test-nick/gitlab-ce@51d18ed4