Skip to content

Commit

Permalink
[#53472] Autocompleters do not find projects with accent when using s…
Browse files Browse the repository at this point in the history
  • Loading branch information
dombesz committed Nov 4, 2024
1 parent 63b49cf commit 16fd72a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { ApiV3Filter } from 'core-app/shared/helpers/api-v3/api-v3-filter-builde
import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
import { ConfigurationService } from 'core-app/core/config/configuration.service';


@Component({
selector: 'opce-header-project-select',
templateUrl: './header-project-select.component.html',
Expand Down Expand Up @@ -75,7 +74,11 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {
.filter(
(project) => {
if (searchText.length) {
const matches = project.name.toLowerCase().includes(searchText.toLowerCase());
// Decompose accented letters such as é or ligatures ff or supertexts ² into basic letters
// and their accents, additionally remove the accents to make the search accent insensitive.
const normalizedProjectName = project.name.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
const normalizedSearchText = searchText.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
const matches = normalizedProjectName.toLowerCase().includes(normalizedSearchText.toLowerCase());

if (!matches) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
.filter(
(project) => {
if (searchText.length) {
const matches = project.name.toLowerCase().includes(searchText.toLowerCase());

// Decompose accented letters such as é or ligatures ff or supertexts ² into basic letters
// and their accents, additionally remove the accents to make the search accent insensitive.
// Where is this being rendered? TODO: Make highlighting work
const normalizedProjectName = project.name.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
const normalizedSearchText = searchText.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
const matches = normalizedProjectName.toLowerCase().includes(normalizedSearchText.toLowerCase());
if (!matches) {
return false;
}
Expand Down
15 changes: 12 additions & 3 deletions spec/features/projects/project_autocomplete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"Very long project name with term at the END",
"INK14 - Foo",
"INK15 - Bar",
"INK16 - Baz"
"INK16 - Baz",
"Prójéct with accents ligatures ff and supertexts ²"
]

names.map do |name|
identifier = name.gsub(/[ -]+/, "-").downcase

identifier = name.gsub(/[ -]+/, "-").downcase.unicode_normalize(:nfkd).gsub(/\p{M}/, "")
create(:project, name:, identifier:)
end
end
Expand Down Expand Up @@ -150,6 +150,15 @@
top_menu.expect_no_result "INK14 - Foo"
top_menu.expect_no_result "INK16 - Baz"

top_menu.search "Project with"
top_menu.expect_result "Prójéct with accents ligatures ff and supertexts ²"

top_menu.search "ff" # Searching for ff should return the ligature ff
top_menu.expect_result "Prójéct with accents ligatures ff and supertexts ²"

top_menu.search "²"
top_menu.expect_result "Prójéct with accents ligatures ff and supertexts ²"

# Visit a project
top_menu.search_and_select "<strong"
top_menu.expect_current_project project2.name
Expand Down

0 comments on commit 16fd72a

Please sign in to comment.