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

Solve search with parameter single=true and no results #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

estercolero82
Copy link

When doing a defiant.search with the option single=true and no results found throws an exception: xres[i] is null. This commit solves the problem.
Sample code:
(async () => {
// import 'defiant'
var defiant = await fetchScript('/res/js/modules/defiant.js');
var data = {
"car": [
{"id": 10, "color": "silver", "name": "Volvo"},
{"id": 11, "color": "red", "name": "Saab"},
{"id": 12, "color": "red", "name": "Peugeot"},
{"id": 13, "color": "yellow", "name": "Porsche"}
],
"bike": [
{"id": 20, "color": "black", "name": "Cannondale"},
{"id": 21, "color": "red", "name": "Shimano"}
]
};

//Search with 0 results looking for a single node
var search = defiant.search(data, '//car[color="brown"]/name', true);
console.log(search);
})();

When doing a defiant.search with the option single=true and no results found throws an exception: xres[i] is null. This commit solves the problem.
Sample code:
(async () => {
  // import 'defiant'
  var defiant = await fetchScript('/res/js/modules/defiant.js');
  var data = {
      "car": [
          {"id": 10, "color": "silver", "name": "Volvo"},
          {"id": 11, "color": "red",    "name": "Saab"},
          {"id": 12, "color": "red",    "name": "Peugeot"},
          {"id": 13, "color": "yellow", "name": "Porsche"}
      ],
      "bike": [
          {"id": 20, "color": "black", "name": "Cannondale"},
          {"id": 21, "color": "red",   "name": "Shimano"}
      ]
  };
  

 //Search with 0 result looking for a single node
  var search = defiant.search(data, '//car[color="brown"]/name', true);
  console.log(search);
})();
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

Successfully merging this pull request may close these issues.

1 participant