Project

General

Profile

Actions

Defect #41096

open

"##" syntax auto complete does not work

Added by Katsuya HIDAKA 11 days ago. Updated 11 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Text formatting
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

When triggered with a text starting with ##, like ##a, the search query becomes #a.

The controller receives #a but returns nothing because there are no issues that match the query.

Below is a part of Rails log when the input is ##a:

Started GET "/issues/auto_complete?project_id=ecookbook&q=%23ab" for 192.168.65.1 at 2024-08-06 01:26:32 +0000
Processing by AutoCompletesController#issues as */*
  Parameters: {"project_id"=>"ecookbook", "q"=>"#a"}
  (snip)
  Issue Load (0.4ms)  SELECT "issues".* FROM "issues" (snip) AND (issues.subject LIKE '%#a%' ESCAPE '\') ORDER BY "issues"."id" DESC LIMIT ?  [["project_id", 1], ["LIMIT", 10]]

I confirmed that this problem occurs in at least Redmine v5.1 and trunk.

Also, due to this problem, the system test 'test_inline_autocomplete_for_issues_with_double_hash_keep_syntax' is currently failing.

Capybara starting Puma...
* Version 6.4.2, codename: The Eagle of Durango
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:38479
...........[Screenshot Image]: /redmine/tmp/screenshots/failures_test_inline_autocomplete_for_issues_with_double_hash_keep_syntax.png
F

Failure:
InlineAutocompleteSystemTest#test_inline_autocomplete_for_issues_with_double_hash_keep_syntax [test/system/inline_autocomplete_test.rb:53]:
Expected false to be truthy.
...
This problem appears to be related to the following issues:

Files

Actions #1

Updated by Katsuya HIDAKA 11 days ago

This patch removes the leading # from the search query so that the controller receives the correct search query.

diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index fcd9aed54..47be33567 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -1164,6 +1164,11 @@ function inlineAutoComplete(element) {
             if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
               $(element).attr('autocomplete', 'off');
             }
+            // When triggered with a text starting with ##, like ##a, the search query will be #a.
+            // To avoid this, remove the first # from the search query.
+            if (text) {
+              text = text.replace(/^#/, '');
+            }
             remoteSearch(getDataSource('issues') + encodeURIComponent(text), function (issues) {
               return cb(issues);
             });

I confirmed that the ## syntax auto complete works correctly in both Redmine v5.1 and the trunk, and that all unit tests and system tests pass.

I also tried adding a new definition for triggering the ## syntax in Tribute. However, I gave up on this approach because I realized that the current implementation of Tribute always references the definition for the # syntax trigger.

Show

Actions

Also available in: Atom PDF