Project

General

Profile

Actions

Defect #41096

closed

"##" syntax auto complete does not work

Added by Katsuya HIDAKA 5 months ago. Updated 4 months ago.

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

0%

Estimated time:
Resolution:
Fixed
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 5 months 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 #2

Updated by Go MAEDA 4 months ago

  • Status changed from New to Confirmed
  • Target version set to 5.1.4

Setting the target version to 5.1.4.

Actions #3

Updated by Massimo Rossello 4 months ago

I think this should be backported to 5.0.x as well

Actions #4

Updated by Go MAEDA 4 months ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix in r23008. Thank you for your contribution.

Actions #5

Updated by Go MAEDA 4 months ago

  • Status changed from Resolved to Closed
  • Target version changed from 5.1.4 to 5.0.10

Merged the fix to stable branches.

Actions #6

Updated by Ko Nagase 4 months ago

Sorry for late, but thanks a lot for this fix!

Actions

Also available in: Atom PDF