Bug in Criteria.stringConditions.ends.search function of searchBuilder

Bug in Criteria.stringConditions.ends.search function of searchBuilder

MikeaMikea Posts: 8Questions: 2Answers: 0
edited October 2020 in Free community support

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Original code in dataTables.searchBuilder.js:

Criteria.stringConditions = {
    'ends': {
        conditionName: 'Ends With',
        init: Criteria.initInput,
        inputValue: Criteria.inputValueInput,
        isInputValid: Criteria.isInputValidInput,
        search: function (value, comparison) {
            return value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length;
        }
}

The search function is not correct.

function search(value, comparison) {
    return (value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length);
}
result = search('ab', ['abc']);
console.log(result);

The result is true, but should be false.
The function should be:

function search(value, comparison) {
    return (value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length)
        && (value.length - comparison[0].length != -1);
}

Or:

function search(value, comparison) {
    return value.toLowerCase().endsWith(comparison[0].toLowerCase());
}

Replies

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @Mikea ,

    Thanks for pointing this out, it appears to be something that we have overlooked. I've raised an issue internally (DD-1705 for my reference) and will report back here when there is an update.

    Thanks,
    Sandy

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @Mikea ,

    That should be the issue fixed now as you can see at this example.

    Thanks again for pointing this out to us,
    Sandy

  • MikeaMikea Posts: 8Questions: 2Answers: 0

    Hi @sandy,
    OK.

This discussion has been closed.