Skip to content

Commit

Permalink
fix: enable the comment in model config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakusaRinne committed Jun 18, 2022
1 parent 820900f commit e011127
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Casbin.UnitTest/examples/basic_model.conf
Original file line number Diff line number Diff line change
@@ -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
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act # Comment, another comment ###
3 changes: 2 additions & 1 deletion Casbin/Model/DefaultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Casbin/PermConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e011127

Please # to comment.