Skip to content

Commit 1b6d755

Browse files
David AndersonDavid Anderson
authored andcommitted
modified groupDynamicSnippetsByRole return type to group dynamic snippets rather than query strings, to handle cases ofa query string having a mixture of safe and unsafe dynamic snippets
1 parent e8be176 commit 1b6d755

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

QCPAnalysis/src/QCPAnalysis/QCP4SubcaseAnalysis.rsc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public void analyzeQCP4(){
3838
types = getQCP4DynamicSnippetTypes(ds) + "superglobal";
3939
println("Types of dynamic snippets: <types>");
4040
println("Counts for each type:\n <(n : size(d) | n <- groupDynamicSnippetsByType(ds), d := groupDynamicSnippetsByType(ds)[n])>");
41-
println("Counts for each role:\n <(n : size(d) | n <- groupQCP4ByRole(qcp4), d := groupQCP4ByRole(qcp4)[n])>");
42-
//for(x <- groupQCP4ByRole(qcp4)["not param"]) println(queryStringToString(x));
41+
println("Counts for each role:\n <(n : size(d) | n <- groupDynamicSnippetsByRole(qcp4), d := groupDynamicSnippetsByRole(qcp4)[n])>");
4342
}
4443

4544
private map[str, list[QuerySnippet]] groupDynamicSnippetsByType(list[QuerySnippet] ds){
@@ -69,13 +68,13 @@ private map[str, list[QuerySnippet]] groupDynamicSnippetsByType(list[QuerySnippe
6968
}
7069

7170
// groups all QCP4 occurrences based on what role their dynamic snippets take on
72-
private map[str, list[QueryString]] groupQCP4ByRole(set[QueryString] qs){
73-
res = ("param" : [], "not param" : []);
71+
private map[str, list[QuerySnippet]] groupDynamicSnippetsByRole(set[QueryString] qs){
72+
res = ("param" : [], "name" : [], "other" : []);
7473
for(q <- qs){
7574
indexes = getDynamicSnippetIndexes(q);
7675

7776
// returns true if this dynamic snippet is used as a parameter
78-
bool parameterSnippet(int i){
77+
bool paramSnippet(int i){
7978
// get previous static snippet
8079
if(staticsnippet(ss) := q.snippets[i - 1]){
8180
// perform regex matching on the static snippet to determine if the dynamic snippet is used as a parameter
@@ -153,16 +152,13 @@ private map[str, list[QueryString]] groupQCP4ByRole(set[QueryString] qs){
153152
return false;
154153
}
155154

156-
// test if all dynamic snippets in q are parameter snippets
157-
bool allParam = true;
158-
for(i <- indexes){
159-
allParam = allParam && (parameterSnippet(i) || valuesParamSnippet(i) || setParamSnippet(i));
160-
}
161-
if(allParam){
162-
res["param"] += q;
163-
}
164-
else{
165-
res["not param"] += q;
155+
for(i <- indexes, ds := q.snippets[i]){
156+
if(paramSnippet(i) || setParamSnippet(i) || valuesParamSnippet(i)){
157+
res["param"] += ds;
158+
}
159+
else{
160+
res["other"] += ds;
161+
}
166162
}
167163
}
168164
return res;

0 commit comments

Comments
 (0)