Skip to content

Commit ba8203b

Browse files
authored
feat: add ExprtkEvaluator test for basic model and root model. (#184)
* 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 <[email protected]> * chore: Update exprtk version Signed-off-by: stonex <[email protected]>
1 parent dc3224c commit ba8203b

File tree

9 files changed

+3465
-2717
lines changed

9 files changed

+3465
-2717
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if(APPLE AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
2828
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version")
2929
endif()
3030

31+
if(WIN32)
32+
add_compile_options("/bigobj")
33+
endif()
34+
3135
###############################################################################
3236
# Project definition.
3337

casbin/enforcer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ bool Enforcer::m_enforce(const std::string& matcher, std::shared_ptr<IEvaluator>
9898
m_log.LogPrint("Policy Rule: ", p_vals);
9999
if(p_tokens.size() != p_vals.size())
100100
return false;
101+
m_func_map.evalator->Clean(m_model->m["p"]);
101102
m_func_map.evalator->InitialObject("p");
102103
for(int j = 0 ; j < p_tokens.size() ; j++) {
103104
size_t index = p_tokens[j].find("_");
@@ -166,6 +167,16 @@ bool Enforcer::m_enforce(const std::string& matcher, std::shared_ptr<IEvaluator>
166167
break;
167168
}
168169
} else {
170+
// Push initial value for p in symbol table
171+
// If p don't in symbol table, the evaluate result will be invalid.
172+
m_func_map.evalator->Clean(m_model->m["p"]);
173+
m_func_map.evalator->InitialObject("p");
174+
for(int j = 0 ; j < p_tokens.size() ; j++) {
175+
size_t index = p_tokens[j].find("_");
176+
std::string token = p_tokens[j].substr(index + 1);
177+
m_func_map.evalator->PushObjectString("p", token, "");
178+
}
179+
169180
bool isvalid = m_func_map.Evaluate(exp_string);
170181
if (!isvalid) {
171182
return false;

0 commit comments

Comments
 (0)