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

fix(Typeahead) highlight displays <strong> tag when empty spaces added at the end of query and does not escape html tags #6434

Merged
merged 3 commits into from
Oct 17, 2024
Merged
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
9 changes: 7 additions & 2 deletions src/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,18 @@ export class TypeaheadContainerComponent implements OnDestroy {
? latinize(itemStr)
: itemStr).toLowerCase();
let startIdx: number;
let tokenLen: number;
let tokenLen = 0;
// Replaces the capture string with the same string inside of a "strong" tag
if (typeof query === 'object') {
const queryLen: number = query.length;
let indexOfTrimmedMatch:number;
for (let i = 0; i < queryLen; i += 1) {
// query[i] is already latinized and lower case
startIdx = itemStrHelper.indexOf(query[i]);
// When user type empty string as query, it always taking first index(0) instead of space after the query word.
// as result it adding the html markup, so to solve this issue we are trimming the match and find the index.
// If it is valid index adding token lenth to it
indexOfTrimmedMatch = itemStrHelper.trim().indexOf(query[i]);
startIdx = query[i].trim() ? itemStrHelper.indexOf(query[i]) : indexOfTrimmedMatch >= 0 ? indexOfTrimmedMatch + tokenLen : -1;
tokenLen = query[i].length;
if (startIdx >= 0 && tokenLen > 0) {
itemStr =
Expand Down
Loading