55import javascript
66import advanced_security.javascript.frameworks.cap.CDS
77
8- abstract class CdlObject extends JsonObject {
9- predicate hasLocationInfo ( string path , int sl , int sc , int el , int ec ) {
10- exists ( Location loc , JsonValue locValue |
11- loc = this .getLocation ( ) and
12- locValue = this .getPropValue ( "$location" ) and
13- path =
14- any ( File f |
15- f .getAbsolutePath ( )
16- .matches ( "%" + locValue .getPropValue ( "file" ) .getStringValue ( ) + ".json" )
17- ) .getAbsolutePath ( ) .regexpReplaceAll ( "\\.json$" , "" ) and
18- sl = locValue .getPropValue ( "line" ) .getIntValue ( ) and
19- sc = locValue .getPropValue ( "col" ) .getIntValue ( ) and
20- el = sl + 1 and
21- ec = 1
22- )
23- }
24- }
8+ abstract class CdlObject extends JsonObject { }
259
2610private newtype CdlKind =
2711 CdlServiceKind ( string value ) { value = "service" } or
@@ -47,6 +31,29 @@ abstract class CdlElement extends CdlObject {
4731
4832 CdlElement ( ) { exists ( CdlDefinition definition | this = definition .getElement ( name ) ) }
4933
34+ predicate hasLocationInfo ( string path , int sl , int sc , int el , int ec ) {
35+ // If the cds.json file has a $location property, then use that,
36+ // otherwise fall back to the cds.json file itself
37+ if exists ( this .getPropValue ( "$location" ) )
38+ then
39+ exists ( Location loc , JsonValue locValue |
40+ loc = this .getLocation ( ) and
41+ locValue = this .getPropValue ( "$location" ) and
42+ path =
43+ any ( File f |
44+ f .getAbsolutePath ( )
45+ .matches ( "%" + locValue .getPropValue ( "file" ) .getStringValue ( ) + ".json" )
46+ ) .getAbsolutePath ( ) .regexpReplaceAll ( "\\.json$" , "" ) and
47+ sl = locValue .getPropValue ( "line" ) .getIntValue ( ) and
48+ sc = locValue .getPropValue ( "col" ) .getIntValue ( ) and
49+ el = sl and
50+ // Currently $locations does not provide an end location. However, we can
51+ // automatically deduce the end location from the length of the name.
52+ ec = sc + getUnqualifiedName ( ) .length ( ) - 1
53+ )
54+ else super .getLocation ( ) .hasLocationInfo ( path , sl , sc , el , ec )
55+ }
56+
5057 /**
5158 * Gets the name of this CDL element.
5259 */
0 commit comments