diff --git a/Casbin.UnitTest/examples/basic_model.conf b/Casbin.UnitTest/examples/basic_model.conf index dc6da813..a6ebcde8 100644 --- a/Casbin.UnitTest/examples/basic_model.conf +++ b/Casbin.UnitTest/examples/basic_model.conf @@ -1,11 +1,11 @@ [request_definition] -r = sub, obj, act +r = sub, obj, act ### The following text is a test for comment in model config. [policy_definition] -p = sub, obj, act +p = sub, obj, act #This is a comment, splited by a comma [policy_effect] -e = some(where (p.eft == allow)) +e = some(where (p.eft == allow))# Comment [matchers] -m = r.sub == p.sub && r.obj == p.obj && r.act == p.act \ No newline at end of file +m = r.sub == p.sub && r.obj == p.obj && r.act == p.act # Comment, another comment ### diff --git a/Casbin/Model/DefaultModel.cs b/Casbin/Model/DefaultModel.cs index c59e9289..040a0b97 100644 --- a/Casbin/Model/DefaultModel.cs +++ b/Casbin/Model/DefaultModel.cs @@ -107,10 +107,11 @@ public bool AddDef(string section, string key, string value) return false; } + int commentStartIdx = value.IndexOf(PermConstants.PolicyCommentChar); var assertion = new Assertion { Key = key, - Value = value + Value = commentStartIdx == -1 ? value : value.Remove(commentStartIdx) }; if (section.Equals(PermConstants.Section.RequestSection) diff --git a/Casbin/PermConstants.cs b/Casbin/PermConstants.cs index f86bc1be..d7ac9499 100644 --- a/Casbin/PermConstants.cs +++ b/Casbin/PermConstants.cs @@ -4,6 +4,7 @@ public static class PermConstants { public const char PolicySeparatorChar = ','; public const string PolicySeparatorString = ", "; // include a white space + public const char PolicyCommentChar = '#'; public const string DefaultRequestType = "r"; public const string RequestType2 = "r2";