diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-22 23:36:07 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-22 23:36:07 +0000 |
commit | fb30039668f68834d9951746181201423fa8b269 (patch) | |
tree | 7a27f3599ea698c3030e3e7d733633ff3fbc4192 /lib | |
parent | 1d85e5fffff66e5b074480d91b414968955b1ee5 (diff) | |
parent | 83d552d50d5485950052a8b9fcba384b81f33c43 (diff) | |
download | gitlab-ce-fb30039668f68834d9951746181201423fa8b269.tar.gz |
Merge branch 'disable-ref-generation-in-code-blocks' into 'master'
Disable reference generation in preformatted/code blocks
### Summary
If a user adds text in code or preformatted text via Markdown or HTML that contains `#XXX`, the system adds a note that issue `XXX` was mentioned. This is particularly annoying because we often list gdb backtrace dumps into our issues, and many issues get mentioned as a result. For example:
```
(gdb) bt
#0 0x00000000004004c4 in second () at main.cc:6
#1 0x00000000004004d2 in first () at main.cc:11
#2 0x00000000004004dd in main () at main.cc:17
(gdb)
```
### Steps to reproduce
1. In an issue, write the above text using Markdown or HTML tags (e.g. `<code>`, `<pre>`).
2. Observe that [issue 1](https://gitlab.com/gitlab-org/gitlab-ce/issues/1) and [issue 2](https://gitlab.com/gitlab-org/gitlab-ce/issues/2) have a note that says they were mentioned.
### Expected behavior
Everything enclosed in the code blocks should be ignored as references.
### Observed behavior
Issues get referenced unnecessarily.
### Fix
I've made `reference_extractor.rb` strip out HTML and Markdown blocks before processing. I considered running the raw text through the entire Markdown processor, but this seems overkill and perhaps could lead to some unintended side effects.
See merge request !365
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/reference_extractor.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index 5b9772de168..1058d4c43d9 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -11,7 +11,13 @@ module Gitlab end def analyze(string, project) - parse_references(string.dup, project) + text = string.dup + + # Remove preformatted/code blocks so that references are not included + text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) { |match| '' } + text.gsub!(%r{^```.*?^```}m) { |match| '' } + + parse_references(text, project) end # Given a valid project, resolve the extracted identifiers of the requested type to |