Skip to content

Commit

Permalink
Support single quotes in conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed Oct 25, 2023
1 parent 336a924 commit d4ee3e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub fn resolve_if(script: &str, data: &JsValue) -> Result<bool, String> {
}
}

let result = match engine.eval_expression_with_scope::<bool>(&mut scope, script) {
let altered = script.replace("'", "\"");

let result = match engine.eval_expression_with_scope::<bool>(&mut scope, &altered) {
Ok(res) => res,
Err(e) => return Err(e.to_string())
};
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ var tests = {
result: true,
script: '["1", "2", "3"].contains(needle)',
data: {'needle': '2'}
},
'test single quotes': {
result: true,
script: 'loader == \'vanilla\'',
data: {'loader': 'vanilla'}
}
}

Expand Down

0 comments on commit d4ee3e7

Please sign in to comment.