@@ -717,13 +717,44 @@ module TestPostProcessing {
717
717
)
718
718
}
719
719
720
+ private string getTagRegex ( ) {
721
+ exists ( string sourceSinkTags |
722
+ (
723
+ getQueryKind ( ) = "problem"
724
+ or
725
+ not exists ( getSourceTag ( _) ) and
726
+ not exists ( getSinkTag ( _) )
727
+ ) and
728
+ sourceSinkTags = ""
729
+ or
730
+ sourceSinkTags = "|" + getSourceTag ( _) + "|" + getSinkTag ( _)
731
+ |
732
+ result = "(Alert" + sourceSinkTags + ")(\\[(.*)\\])?"
733
+ )
734
+ }
735
+
720
736
/**
721
737
* A configuration for matching `// $ Source=foo` comments against actual
722
738
* path-problem sources.
739
+ *
740
+ * Whenever a source is tagged with a value, like `foo`, we will use that
741
+ * to define the expected tags at the sink and the alert.
723
742
*/
724
743
private module PathProblemSourceTestInput implements TestSig {
725
744
string getARelevantTag ( ) { result = getSourceTag ( _) }
726
745
746
+ bindingset [ expectedTag, actualTag]
747
+ predicate tagMatches ( string expectedTag , string actualTag ) {
748
+ actualTag = expectedTag .regexpCapture ( getTagRegex ( ) , 1 ) and
749
+ (
750
+ // expected tag is annotated with a query ID
751
+ getQueryId ( ) = expectedTag .regexpCapture ( getTagRegex ( ) , 3 )
752
+ or
753
+ // expected tag is not annotated with a query ID
754
+ not exists ( expectedTag .regexpCapture ( getTagRegex ( ) , 3 ) )
755
+ )
756
+ }
757
+
727
758
bindingset [ expectedValue, actualValue]
728
759
predicate valueMatches ( string expectedValue , string actualValue ) {
729
760
exists ( expectedValue ) and
@@ -754,28 +785,7 @@ module TestPostProcessing {
754
785
bindingset [ result ]
755
786
string getARelevantTag ( ) { any ( ) }
756
787
757
- private string getTagRegex ( ) {
758
- exists ( string sourceSinkTags |
759
- getQueryKind ( ) = "problem" and
760
- sourceSinkTags = ""
761
- or
762
- sourceSinkTags = "|" + getSourceTag ( _) + "|" + getSinkTag ( _)
763
- |
764
- result = "(Alert" + sourceSinkTags + ")(\\[(.*)\\])?"
765
- )
766
- }
767
-
768
- bindingset [ expectedTag, actualTag]
769
- predicate tagMatches ( string expectedTag , string actualTag ) {
770
- actualTag = expectedTag .regexpCapture ( getTagRegex ( ) , 1 ) and
771
- (
772
- // expected tag is annotated with a query ID
773
- getQueryId ( ) = expectedTag .regexpCapture ( getTagRegex ( ) , 3 )
774
- or
775
- // expected tag is not annotated with a query ID
776
- not exists ( expectedTag .regexpCapture ( getTagRegex ( ) , 3 ) )
777
- )
778
- }
788
+ predicate tagMatches = PathProblemSourceTestInput:: tagMatches / 2 ;
779
789
780
790
bindingset [ expectedTag]
781
791
predicate tagIsOptional ( string expectedTag ) {
@@ -789,64 +799,58 @@ module TestPostProcessing {
789
799
)
790
800
}
791
801
792
- bindingset [ expectedValue, actualValue]
793
- predicate valueMatches ( string expectedValue , string actualValue ) {
794
- expectedValue = actualValue
795
- or
796
- actualValue = ""
797
- }
798
-
799
802
private predicate hasPathProblemSource = PathProblemSourceTestInput:: hasPathProblemSource / 5 ;
800
803
801
- /**
802
- * Gets the expected sink value for result row `row`. This value must
803
- * match the value at the corresponding path-problem source (if it is
804
- * present).
805
- */
806
- private string getSinkValue ( int row ) {
807
- exists ( Input:: Location location , string element , string tag , string val |
808
- hasPathProblemSource ( row , location , element , tag , val ) and
809
- result =
810
- PathProblemSourceTest:: getAMatchingExpectation ( location , element , tag , val , false )
811
- .getValue ( )
812
- )
813
- }
814
-
815
804
private predicate hasPathProblemSink (
816
- int row , Input:: Location location , string element , string tag , string value
805
+ int row , Input:: Location location , string element , string tag
817
806
) {
818
807
getQueryKind ( ) = "path-problem" and
819
808
exists ( string loc |
820
809
queryResults ( "#select" , row , 4 , loc ) and
821
810
queryResults ( "#select" , row , 5 , element ) and
822
811
tag = getSinkTag ( row ) and
823
812
Input2:: getRelativeUrl ( location ) = loc
824
- |
825
- not exists ( getSinkValue ( row ) ) and value = ""
826
- or
827
- value = getSinkValue ( row )
828
813
)
829
814
}
830
815
831
- private predicate hasAlert ( Input:: Location location , string element , string tag , string value ) {
816
+ private predicate hasAlert ( int row , Input:: Location location , string element , string tag ) {
832
817
getQueryKind ( ) = [ "problem" , "path-problem" ] and
833
- exists ( int row , string loc |
818
+ exists ( string loc |
834
819
queryResults ( "#select" , row , 0 , loc ) and
835
820
queryResults ( "#select" , row , 2 , element ) and
836
821
tag = "Alert" and
837
- value = "" and
838
822
Input2:: getRelativeUrl ( location ) = loc and
839
823
not hasPathProblemSource ( row , location , _, _, _) and
840
- not hasPathProblemSink ( row , location , _, _, _)
824
+ not hasPathProblemSink ( row , location , _, _)
825
+ )
826
+ }
827
+
828
+ /**
829
+ * Gets the expected value for result row `row`, if any. This value must
830
+ * match the value at the corresponding path-problem source (if it is
831
+ * present).
832
+ */
833
+ private string getValue ( int row ) {
834
+ exists ( Input:: Location location , string element , string tag , string val |
835
+ hasPathProblemSource ( row , location , element , tag , val ) and
836
+ result =
837
+ PathProblemSourceTest:: getAMatchingExpectation ( location , element , tag , val , false )
838
+ .getValue ( )
841
839
)
842
840
}
843
841
844
842
predicate hasActualResult ( Input:: Location location , string element , string tag , string value ) {
845
- hasPathProblemSource ( _, location , element , tag , value )
846
- or
847
- hasPathProblemSink ( _, location , element , tag , value )
848
- or
849
- hasAlert ( location , element , tag , value )
843
+ exists ( int row |
844
+ hasPathProblemSource ( row , location , element , tag , _)
845
+ or
846
+ hasPathProblemSink ( row , location , element , tag )
847
+ or
848
+ hasAlert ( row , location , element , tag )
849
+ |
850
+ not exists ( getValue ( row ) ) and value = ""
851
+ or
852
+ value = getValue ( row )
853
+ )
850
854
}
851
855
}
852
856
0 commit comments