$regex automatically added to Parse.com search prameter


#1

Buidling an app using Parse.com for the backend. The app has been functioning fine on the emulator and on Android.

However after loading the app on an iPhone (tried it on a 4S, 5, 5S and 6), the User Query returns an empty array.

Here is the code:

var userquery = new Parse.Query(Parse.User);
userquery.startsWith("username", $scope.search.queryvalue);
userquery.notEqualTo("username", $rootScope.sessionUser.get("username"));
userquery.limit(20);
console.log("QueryVal: " + $scope.search.queryvalue);
console.log("UserQuery: " + JSON.stringify(userquery));
userquery.find({
  success: function(result) {
    $scope.people = result;
  },
  error: function(error) {
    console.log("error");
  }
});

As mentioned before, this code returns the right result when using the iOS Emulator and when testing the app on an Android Device. However on an iPhone is does not work.

After doing some more testing with some console logs I found another error. The problem is that the variable that is taken in through an input text box adds some strange REGEX parameters.

The search input box text was tanuj

The console output from an iPhone looks like this:

QueryVal: tanuj
UserQuery: {"where":{"username":{"$regex":"^\\Qtanuj\\E","$ne":"test"},"id":{"$ne":"46JOEKKKF1"}},"limit":20}

Anyone know why {"$regex":"^\\Q and \\E" is being added around the search query value tanuj?

Again, this is only happening on an iPhone. Could this be an AngularJS issue? Is there a way to force AngularJS to not put the variable through regex?


#2

Decided to see what the console logs for the emulator are. So here are the console logs from the emulator:

QueryVal: tanuj
UserQuery new: {"where":{"username":{"$regex":"^\\Qtanuj\\E","$ne":"test"},"id":{"$ne":"46JOEKKKF1"}},"limit":20}

This is boggling my mind. The values work even with the $regex bit while on the emulator. But as soon as it goes on the phone, the result is blank.

This is the console logs of the result on the iPhone: result: []

But on the emulator, it returns the expected values.

What could the problem be?