Skip to content

Commit 0bb5423

Browse files
Merge pull request #806 from g-maxime/contains
Add 'contains' and 'must not contain' operators
2 parents b73a4a6 + aefd7d4 commit 0bb5423

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

Source/Checker/Checker.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ bool PolicyChecker::RuleElement::compare(const std::string& v1, const std::stri
320320
{
321321
to_return = v2.rfind(v1, 0) != 0;
322322
}
323+
else if (operand=="contains")
324+
{
325+
to_return = v2.find(v1) != std::string::npos;
326+
}
327+
else if (operand=="must not contain")
328+
{
329+
to_return = v2.find(v1) == std::string::npos;
330+
}
323331
else if (operand == "<")
324332
{
325333
if (!strlen(val_end) && !strlen(ref_end))
@@ -399,7 +407,7 @@ void PolicyChecker::RuleElement::resolve()
399407
else // keep old behavior for legacy "*" value
400408
pass=values.empty();
401409
}
402-
else if (operand=="starts with" || operand=="must not start with" || operand=="<" || operand=="<=" || operand=="=" || operand=="!=" || operand==">=" || operand==">")
410+
else if (operand=="starts with" || operand=="must not start with" || operand=="contains" || operand=="must not contain" || operand=="<" || operand=="<=" || operand=="=" || operand=="!=" || operand==">=" || operand==">")
403411
{
404412
std::vector<bool> results;
405413

Source/Common/generated/PolicyTransformXml.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const char policy_transform_xml[] = {
234234
,'\x0a'
235235
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x2f','\x61','\x6c','\x69','\x61','\x73','\x78','\x73','\x6c','\x3a','\x69','\x66','\x3e','\x0d'
236236
,'\x0a'
237-
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x61','\x6c','\x69','\x61','\x73','\x78','\x73','\x6c','\x3a','\x69','\x66','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x24','\x70','\x6f','\x6c','\x69','\x63','\x79','\x5f','\x76','\x65','\x72','\x62','\x6f','\x73','\x69','\x74','\x79','\x3e','\x30','\x20','\x6f','\x72','\x20','\x24','\x6f','\x75','\x74','\x63','\x6f','\x6d','\x65','\x21','\x3d','\x27','\x70','\x61','\x73','\x73','\x27','\x20','\x6f','\x72','\x20','\x73','\x74','\x72','\x69','\x6e','\x67','\x2d','\x6c','\x65','\x6e','\x67','\x74','\x68','\x28','\x24','\x63','\x6f','\x6d','\x70','\x61','\x72','\x65','\x64','\x5f','\x74','\x6f','\x29','\x3e','\x30','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x73','\x74','\x61','\x72','\x74','\x73','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x22','\x3e','\x0d'
237+
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x61','\x6c','\x69','\x61','\x73','\x78','\x73','\x6c','\x3a','\x69','\x66','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x24','\x70','\x6f','\x6c','\x69','\x63','\x79','\x5f','\x76','\x65','\x72','\x62','\x6f','\x73','\x69','\x74','\x79','\x3e','\x30','\x20','\x6f','\x72','\x20','\x24','\x6f','\x75','\x74','\x63','\x6f','\x6d','\x65','\x21','\x3d','\x27','\x70','\x61','\x73','\x73','\x27','\x20','\x6f','\x72','\x20','\x73','\x74','\x72','\x69','\x6e','\x67','\x2d','\x6c','\x65','\x6e','\x67','\x74','\x68','\x28','\x24','\x63','\x6f','\x6d','\x70','\x61','\x72','\x65','\x64','\x5f','\x74','\x6f','\x29','\x3e','\x30','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x73','\x74','\x61','\x72','\x74','\x73','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x73','\x27','\x20','\x6f','\x72','\x20','\x24','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x27','\x22','\x3e','\x0d'
238238
,'\x0a'
239239
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x61','\x6c','\x69','\x61','\x73','\x78','\x73','\x6c','\x3a','\x69','\x66','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x24','\x72','\x65','\x71','\x75','\x65','\x73','\x74','\x65','\x64','\x22','\x3e','\x0d'
240240
,'\x0a'
@@ -610,6 +610,10 @@ const char policy_transform_xml[] = {
610610
,'\x0a'
611611
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x22','\x3e','\x6e','\x6f','\x74','\x28','\x73','\x74','\x61','\x72','\x74','\x73','\x2d','\x77','\x69','\x74','\x68','\x28','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x3e','\x0d'
612612
,'\x0a'
613+
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x73','\x27','\x22','\x3e','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x73','\x28','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x3e','\x0d'
614+
,'\x0a'
615+
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x27','\x22','\x3e','\x6e','\x6f','\x74','\x28','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x73','\x28','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x3e','\x0d'
616+
,'\x0a'
613617
,'\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x63','\x68','\x6f','\x6f','\x73','\x65','\x3e','\x0d'
614618
,'\x0a'
615619
,'\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x76','\x61','\x6c','\x75','\x65','\x2d','\x6f','\x66','\x20','\x73','\x65','\x6c','\x65','\x63','\x74','\x3d','\x22','\x24','\x65','\x71','\x75','\x61','\x74','\x69','\x6f','\x6e','\x62','\x61','\x73','\x65','\x22','\x2f','\x3e','\x0d'
@@ -620,15 +624,15 @@ const char policy_transform_xml[] = {
620624
,'\x0a'
621625
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x65','\x78','\x69','\x73','\x74','\x27','\x22','\x3e','\x29','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x3e','\x0d'
622626
,'\x0a'
623-
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x73','\x74','\x61','\x72','\x74','\x73','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x22','\x3e','\x0d'
627+
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x73','\x74','\x61','\x72','\x74','\x73','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x73','\x27','\x20','\x6f','\x72','\x20','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x27','\x22','\x3e','\x0d'
624628
,'\x0a'
625629
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x74','\x65','\x78','\x74','\x3e','\x2c','\x27','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x74','\x65','\x78','\x74','\x3e','\x0d'
626630
,'\x0a'
627631
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x76','\x61','\x6c','\x75','\x65','\x2d','\x6f','\x66','\x20','\x73','\x65','\x6c','\x65','\x63','\x74','\x3d','\x22','\x2e','\x22','\x2f','\x3e','\x0d'
628632
,'\x0a'
629633
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x74','\x65','\x78','\x74','\x3e','\x27','\x29','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x74','\x65','\x78','\x74','\x3e','\x0d'
630634
,'\x0a'
631-
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x69','\x66','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x22','\x3e','\x29','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x69','\x66','\x3e','\x0d'
635+
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x78','\x73','\x6c','\x3a','\x69','\x66','\x20','\x74','\x65','\x73','\x74','\x3d','\x22','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x73','\x74','\x61','\x72','\x74','\x20','\x77','\x69','\x74','\x68','\x27','\x20','\x6f','\x72','\x20','\x40','\x6f','\x70','\x65','\x72','\x61','\x74','\x6f','\x72','\x3d','\x27','\x6d','\x75','\x73','\x74','\x20','\x6e','\x6f','\x74','\x20','\x63','\x6f','\x6e','\x74','\x61','\x69','\x6e','\x27','\x22','\x3e','\x29','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x69','\x66','\x3e','\x0d'
632636
,'\x0a'
633637
,'\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x20','\x3c','\x2f','\x78','\x73','\x6c','\x3a','\x77','\x68','\x65','\x6e','\x3e','\x0d'
634638
,'\x0a'

Source/Resource/html/xslPolicy.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ <h4>Actions:</h4>
208208
<option value="&gt;=">Is greater or equal than (&gt;=)</option>
209209
<option value="starts with">Starts with</option>
210210
<option value="must not start with">Must not start with</option>
211+
<option value="contains">Contains</option>
212+
<option value="must not contain">Must not contain</option>
211213
</select>
212214
</div>
213215
<div class="form-group">

Tools/Policies/policyset2policytransform2policyresult.xsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<aliasxsl:value-of select="$level"/>
111111
</aliasxsl:attribute>
112112
</aliasxsl:if>
113-
<aliasxsl:if test="$policy_verbosity>0 or $outcome!='pass' or string-length($compared_to)>0 or $operator='starts with' or $operator='must not start with'">
113+
<aliasxsl:if test="$policy_verbosity>0 or $outcome!='pass' or string-length($compared_to)>0 or $operator='starts with' or $operator='must not start with' or $operator='contains' or $operator='must not contain'">
114114
<aliasxsl:if test="$requested">
115115
<aliasxsl:attribute name="requested">
116116
<aliasxsl:value-of select="$requested"/>
@@ -298,16 +298,18 @@
298298
<xsl:when test="@operator='must not exist'">not(</xsl:when>
299299
<xsl:when test="@operator='starts with'">starts-with(</xsl:when>
300300
<xsl:when test="@operator='must not start with'">not(starts-with(</xsl:when>
301+
<xsl:when test="@operator='contains'">contains(</xsl:when>
302+
<xsl:when test="@operator='must not contain'">not(contains(</xsl:when>
301303
</xsl:choose>
302304
<xsl:value-of select="$equationbase"/>
303305
<xsl:choose>
304306
<xsl:when test="not(@operator) or @operator='exists'"></xsl:when>
305307
<xsl:when test="@operator='must not exist'">)</xsl:when>
306-
<xsl:when test="@operator='starts with' or @operator='must not start with'">
308+
<xsl:when test="@operator='starts with' or @operator='must not start with' or @operator='contains' or @operator='must not contain'">
307309
<xsl:text>,'</xsl:text>
308310
<xsl:value-of select="."/>
309311
<xsl:text>')</xsl:text>
310-
<xsl:if test="@operator='must not start with'">)</xsl:if>
312+
<xsl:if test="@operator='must not start with' or @operator='must not contain'">)</xsl:if>
311313
</xsl:when>
312314
<xsl:when test="@operator">
313315
<xsl:value-of select="@operator"/>

0 commit comments

Comments
 (0)