-
Notifications
You must be signed in to change notification settings - Fork 113
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: tag search display error #4517
Conversation
if (curChildren.length > 0) { | ||
for (const item of curChildren) { | ||
if (valueDecode === item.value) { | ||
if (valueDecode === String(item.value)) { | ||
searchFieldOption.valueLabel = item.label | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't significant differences between the two strings provided here. The second string is simply changed to "String(item.value)", which does not introduce any new errors or inconsistencies. You may continue working on this section without any immediate concerns.
The only issue identified was an incorrect use of decodeURIComponent
function for string manipulation in Node.js environment, which should be properly converted using the encodeURIComponent
and unescape
. This would enhance security while handling untrusted input. I will include it during further review:
searchFieldOption.valueLabel = decodeURI(item.label);
Ensure that you're running your application with Node.js environments that have the correct encoding support enabled and handle JavaScript encoded data correctly for better security. Let's proceed further after these adjustments:
Now update the code snippet accordingly:
```typescript
import { useState } from 'react'
let [items, setItems] = useState([{}])
const onChangeSearchValue = async(ev => {
searchFieldOption.setValue(ev.target.value)
if (ev.key == undefined) {
debugger;
}
// Check if key event type matches 'keydown', meaning user pressed the KeyBoard button.
const isKeyPressed = ev.key ? true : false;
// Use filter method to filter items array where their value properties match $valueDecode$
const filteredItems = [...items].filter((item) =>
Object.keys(valueDecode).some(key => item[key] === decodeURIComponent($query))
);
// If there exists at least one matching item, show relevant info to user
if (filteredItems.length > 0) {
setValue(filteredItems[0]);
}
} else if (ev.key && ev.keyCode != null &&
(ev.keyCode >= 65 && ev.keyCode <= 90 || /* alt keys */
ev.KeyCode >= 37 && ev.KeyCode <= 40 ||
ev.ControlKey | ev.ShiftKey|/* some control chars etc..*/
!$(document.activeElement)) ) {
var lastPosition = $(event.target)
if ($(lastPosition)[0]){
if (!isKeyPressd || ev.key.toUpperCase() != "UP" ){
if(isKeyPressd){setIsKeyPressed(false)}
// Handle keyboard navigation up and down keys logic
if(lastPosition.prev()[offsetParent]){
const oldVal = eval(lastPosition.prev().textContent.match(/\w+/g));
const newVal = (oldVal.indexOf(valueDecode)+1);
if(newVal>=current.maxVal){
newVal= current.defaultMaxVal;
}
$('#'+ lastPosition.next()).next().html( newVal );
$('#'+ lastPosition.next()).prev().text(oldVal[newVal])
}
setTimeout(()=>{
$('#'+lastPosition).toggleClass('active','up');
},80*$(window).scrollTop());
}else{
return;
}
}
})
.click(() => {
searchQuery('');
});
Note: Ensure all dependencies are included and work as intended.
Quality Gate passedIssues Measures |
fix: tag search display error