Skip to content

Commit cd38826

Browse files
author
Stephan Brandauer
committed
use new DollarAtString class to return metadata using notation
1 parent 6be11d9 commit cd38826

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

java/ql/src/Telemetry/AutomodelFrameworkModeExtractCandidates.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
private import AutomodelFrameworkModeCharacteristics
16+
private import AutomodelSharedUtil
1617

1718
from
1819
Endpoint endpoint, string message, MetadataExtractor meta, string package, string type,
@@ -41,5 +42,9 @@ select endpoint,
4142
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
4243
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
4344
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
44-
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
45-
"signature", input.toString(), "input" //
45+
package.(DollarAtString), "package", //
46+
type.(DollarAtString), "type", //
47+
subtypes.toString().(DollarAtString), "subtypes", //
48+
name.(DollarAtString), "name", //
49+
signature.(DollarAtString), "signature", //
50+
input.toString().(DollarAtString), "input" //

java/ql/src/Telemetry/AutomodelFrameworkModeExtractNegativeExamples.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
private import AutomodelFrameworkModeCharacteristics
1212
private import AutomodelEndpointTypes
13+
private import AutomodelSharedUtil
1314

1415
from
1516
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
@@ -38,5 +39,9 @@ select endpoint,
3839
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
3940
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
4041
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
41-
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
42-
"signature", input.toString(), "input" //
42+
package.(DollarAtString), "package", //
43+
type.(DollarAtString), "type", //
44+
subtypes.toString().(DollarAtString), "subtypes", //
45+
name.(DollarAtString), "name", //
46+
signature.(DollarAtString), "signature", //
47+
input.toString().(DollarAtString), "input" //

java/ql/src/Telemetry/AutomodelFrameworkModeExtractPositiveExamples.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
private import AutomodelFrameworkModeCharacteristics
1212
private import AutomodelEndpointTypes
13+
private import AutomodelSharedUtil
1314

1415
from
1516
Endpoint endpoint, SinkType sinkType, MetadataExtractor meta, string package, string type,
@@ -25,5 +26,9 @@ select endpoint,
2526
sinkType + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
2627
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
2728
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
28-
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
29-
"signature", input.toString(), "input" //
29+
package.(DollarAtString), "package", //
30+
type.(DollarAtString), "type", //
31+
subtypes.toString().(DollarAtString), "subtypes", //
32+
name.(DollarAtString), "name", //
33+
signature.(DollarAtString), "signature", //
34+
input.toString().(DollarAtString), "input" //
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Helper class to represent a string value that can be returned by a query using $@ notation.
3+
*
4+
* It extends `string`, but adds a mock `getURL` method that returns the string itself as a data URL.
5+
*
6+
* Use this, when you want to return a string value from a query using $@ notation — the string value
7+
* will be included in the sarif file.
8+
*
9+
* Note that the string should be URL-encoded, or the resulting URL will be invalid (this may be OK in your use case).
10+
*
11+
* Background information:
12+
* - data URLs: https://developer.mozilla.org/en-US/docs/web/http/basics_of_http/data_urls
13+
* - `getURL`:
14+
* https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/#providing-urls
15+
*/
16+
class DollarAtString extends string {
17+
bindingset[this]
18+
DollarAtString() { any() }
19+
20+
bindingset[this]
21+
string getURL() { result = "data:text/plain," + this }
22+
}

0 commit comments

Comments
 (0)