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

Unexpected behavior when using multiple conditions #33

Closed
BlackWiCKED opened this issue Feb 17, 2015 · 3 comments
Closed

Unexpected behavior when using multiple conditions #33

BlackWiCKED opened this issue Feb 17, 2015 · 3 comments

Comments

@BlackWiCKED
Copy link
Contributor

I have spotted something strange when trying to connect multiple conditions with OR operator.

Demonstration of the issue:

XPATH EVALUATOR with default data:

//*[contains(title, "The") or contains(author, "Evelyn")]
Returns only 2 items - those which have the word "the" in their title.

//*[contains(title, "The") or contains(author, "velyn")]
Surprisingly it works when I delete the first character from the author condition.
All 3 items are returned in this case.

Must be some kind of problem with the regex replace. I will try to locate and fix it.

@hbi99
Copy link
Owner

hbi99 commented Feb 17, 2015

Hi @BlackWiCKED,
Thanks for the issue...actually, there is an regexp that automatically changes contains to case-insensitive. Look at this file;

https://github.com/hbi99/defiant.js/blob/master/src/string.js

I can fix this in a couple of hours...

@BlackWiCKED
Copy link
Contributor Author

Actually, looks like it was easier to find than I thought. There is only one missing /g in the replace function to replace all occurrences of contains(). It works now.

https://raw.githubusercontent.com/hbi99/defiant.js/master/dist/defiant-latest.js

/contains\(([^,]+),([^\\)]+)\)/g
if (!String.prototype.xTransform) {
    String.prototype.xTransform = function () {
        var str = this;
        if (this.indexOf('translate(') === -1) {
            str = this.replace(/contains\(([^,]+),([^\\)]+)\)/g, function(c,h,n) {
                var a = 'abcdefghijklmnopqrstuvwxyz',
                    q = n.trim().slice(-1);
                return "contains(translate("+ h +", "+ q + a.toUpperCase() + q +", "+ q + a + q +"),"+ n.toLowerCase() +")";
            });
        }
        return str.toString();
    };
}

@BlackWiCKED
Copy link
Contributor Author

Shall I send a proper pull request? I have not forked the original repository yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants