Handle #{ in Engine::parse_json, restrict to object hashes only.

This commit is contained in:
Stephen Chung
2020-08-18 23:07:17 +08:00
parent 111f5931b3
commit c5360db185
4 changed files with 82 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
#![cfg(not(feature = "no_object"))]
use rhai::{Engine, EvalAltResult, Map, Scope, INT};
use rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT};
#[test]
fn test_map_indexing() -> Result<(), Box<EvalAltResult>> {
@@ -182,6 +182,14 @@ fn test_map_json() -> Result<(), Box<EvalAltResult>> {
);
}
engine.parse_json(&format!("#{}", json), true)?;
assert!(matches!(
*engine.parse_json(" 123", true).expect_err("should error"),
EvalAltResult::ErrorParsing(ParseErrorType::MissingToken(token, _), pos)
if token == "{" && pos.position() == Some(4)
));
Ok(())
}