Skip to content

Commit

Permalink
feat: add ExprtkEvaluator test for basic model and root model. (#184)
Browse files Browse the repository at this point in the history
* feat: add ExprtkEvaluator test for basic model and root model.

fix: fix basic_with_root_model.conf and add "p" variable when Enforce
with no policy.

fix: add bigobj option for windows.

fix: fix short string optimization bug in MSVC.

Signed-off-by: stonexx <1479765922@qq.com>

* chore: Update exprtk version

Signed-off-by: stonex <1479765922@qq.com>
  • Loading branch information
sheny1xuan authored Feb 22, 2022
1 parent dc3224c commit ba8203b
Show file tree
Hide file tree
Showing 9 changed files with 3,465 additions and 2,717 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if(APPLE AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version")
endif()

if(WIN32)
add_compile_options("/bigobj")
endif()

###############################################################################
# Project definition.

Expand Down
11 changes: 11 additions & 0 deletions casbin/enforcer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bool Enforcer::m_enforce(const std::string& matcher, std::shared_ptr<IEvaluator>
m_log.LogPrint("Policy Rule: ", p_vals);
if(p_tokens.size() != p_vals.size())
return false;
m_func_map.evalator->Clean(m_model->m["p"]);
m_func_map.evalator->InitialObject("p");
for(int j = 0 ; j < p_tokens.size() ; j++) {
size_t index = p_tokens[j].find("_");
Expand Down Expand Up @@ -166,6 +167,16 @@ bool Enforcer::m_enforce(const std::string& matcher, std::shared_ptr<IEvaluator>
break;
}
} else {
// Push initial value for p in symbol table
// If p don't in symbol table, the evaluate result will be invalid.
m_func_map.evalator->Clean(m_model->m["p"]);
m_func_map.evalator->InitialObject("p");
for(int j = 0 ; j < p_tokens.size() ; j++) {
size_t index = p_tokens[j].find("_");
std::string token = p_tokens[j].substr(index + 1);
m_func_map.evalator->PushObjectString("p", token, "");
}

bool isvalid = m_func_map.Evaluate(exp_string);
if (!isvalid) {
return false;
Expand Down
Loading

0 comments on commit ba8203b

Please sign in to comment.