Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#53472] Autocompleters do not find projects with accent #17109

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export default class FilterListController extends Controller {
}

filterLists() {
const query = this.filterTarget.value.toLowerCase();
const query = this.filterTarget.value.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
let showNoResultsText = true;

this.searchItemTargets.forEach((item) => {
const text = item.textContent?.toLowerCase();
const text = item.textContent?.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase();

if (text?.includes(query)) {
this.setVisibility(item, true);
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