Skip to content

Commit 22a7dff

Browse files
committed
fix(service-patterns): end the Angular receiver rows at a separator (DeusData#2768)
The new HttpClient receiver rows matched by prefix, and an uppercase letter after an id counts as CamelCase glue, so "this.http" also matched this.httpAdapter.get (a NestJS route registration) and this.httpServer.post, and "$http" matched $httpBackend.expectGET (an AngularJS test double). Each receiver row now ends in a dot, like "gin.", plus a line-break twin (LF, and CR for CRLF files): a chain wrapped before the verb keeps the break in its callee text ("this.http\n .post"). On gothinkster/angular-realworld-example-app 5 of the 18 client calls are written that way; with dot-only rows they fell back to phantom route registrations. "HttpClient" duplicated the Java/C# row and "this.httpClient." is covered by "httpClient.". Unit cases pin both directions, and the Angular pipeline test gains a wrapped call on both resolver routes. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent c548d8e commit 22a7dff

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎internal/cbm/service_patterns.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,25 @@ static const lib_pattern_t http_libraries[] = {
4646
* case-sensitive, so without this entry `Axios.get(url)` fell through to
4747
* the `.get` route-suffix fallback and became a route registration. */
4848
{"Axios", CBM_SVC_HTTP, NULL},
49+
/* Angular HttpClient (#2768). The receiver rows end in a dot, like "gin.":
50+
* a bare "this.http" / "$http" would also match this.httpAdapter.get
51+
* (NestJS route registration) and $httpBackend.expectGET (an AngularJS test
52+
* double), because an uppercase letter after an id counts as CamelCase
53+
* glue. A chain wrapped before the verb keeps its line break in the callee
54+
* text ("this.http\n .post", prettier's style), so each receiver also
55+
* has a line-break twin: LF, and CR for CRLF files. Java/C# HttpClient is
56+
* already listed below. */
4957
{"@angular/common/http", CBM_SVC_HTTP, NULL},
5058
{"angular.common.http", CBM_SVC_HTTP, NULL},
51-
{"HttpClient", CBM_SVC_HTTP, NULL},
52-
{"httpClient", CBM_SVC_HTTP, NULL},
53-
{"this.http", CBM_SVC_HTTP, NULL},
54-
{"this.httpClient", CBM_SVC_HTTP, NULL},
55-
{"$http", CBM_SVC_HTTP, NULL},
59+
{"this.http.", CBM_SVC_HTTP, NULL},
60+
{"this.http\n", CBM_SVC_HTTP, NULL},
61+
{"this.http\r", CBM_SVC_HTTP, NULL},
62+
{"httpClient.", CBM_SVC_HTTP, NULL},
63+
{"httpClient\n", CBM_SVC_HTTP, NULL},
64+
{"httpClient\r", CBM_SVC_HTTP, NULL},
65+
{"$http.", CBM_SVC_HTTP, NULL},
66+
{"$http\n", CBM_SVC_HTTP, NULL},
67+
{"$http\r", CBM_SVC_HTTP, NULL},
5668
{"superagent", CBM_SVC_HTTP, NULL},
5769
{"needle", CBM_SVC_HTTP, NULL},
5870
{"node-fetch", CBM_SVC_HTTP, NULL},

‎tests/test_infrascan.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ TEST(infrascan_service_pattern_match_rejects_ids_inside_words) {
173173
{"kafkaesque.story.tell", CBM_SVC_NONE},
174174
/* "Axios" glued to a lowercase continuation */
175175
{"geo.Axiosphere.map", CBM_SVC_NONE},
176+
/* Angular receiver rows end in a dot (#2768): a longer receiver that
177+
* only starts with the same letters is not the HttpClient (NestJS
178+
* route registration, AngularJS test double) */
179+
{"this.httpAdapter.get", CBM_SVC_NONE},
180+
{"this.httpServer.post", CBM_SVC_NONE},
181+
{"$httpBackend.expectGET", CBM_SVC_NONE},
182+
{"this.httpAdapter\n .get", CBM_SVC_NONE},
176183
{NULL, CBM_SVC_NONE},
177184
};
178185
ASSERT_EQ(svc_case_mismatches(cases), 0);
@@ -202,6 +209,18 @@ TEST(infrascan_service_pattern_match_keeps_real_library_qns) {
202209
{"Axios.post", CBM_SVC_HTTP},
203210
{"AxiosInstance.get", CBM_SVC_HTTP},
204211
{"curl_exec", CBM_SVC_HTTP},
212+
/* Angular HttpClient receivers (#2768); `_httpClient` is the common
213+
* C# field spelling of the same client */
214+
{"this.http.get", CBM_SVC_HTTP},
215+
{"this.httpClient.post", CBM_SVC_HTTP},
216+
{"httpClient.put", CBM_SVC_HTTP},
217+
{"_httpClient.GetAsync", CBM_SVC_HTTP},
218+
{"$http.get", CBM_SVC_HTTP},
219+
/* a chain wrapped before the verb keeps the line break (LF / CRLF) */
220+
{"this.http\n .post", CBM_SVC_HTTP},
221+
{"this.http\r\n .delete", CBM_SVC_HTTP},
222+
{"this.httpClient\n .put", CBM_SVC_HTTP},
223+
{"$http\n .get", CBM_SVC_HTTP},
205224
{"surf.get", CBM_SVC_HTTP},
206225
{"hyper.Client.request", CBM_SVC_HTTP},
207226
{"phin.promisified", CBM_SVC_HTTP},

‎tests/test_pipeline.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14972,6 +14972,11 @@ static int angular_http_client_typed_case(int fillers) {
1497214972
" deleteItem(id: string) {\n"
1497314973
" return this.http.delete(`/items/${id}`);\n"
1497414974
" }\n"
14975+
"\n"
14976+
" updateItem(id: string, item: any) {\n"
14977+
" return this.http\n"
14978+
" .put(`/items/${id}`, item);\n"
14979+
" }\n"
1497514980
"}\n");
1497614981

1497714982
for (int i = 0; i < fillers; i++) {
@@ -15002,6 +15007,9 @@ static int angular_http_client_typed_case(int fillers) {
1500215007
ASSERT_EQ(http_calls_to_route(s, project, "getItem", "__route__GET__/items/{}"), 1);
1500315008
ASSERT_EQ(http_calls_to_route(s, project, "createItem", "__route__POST__/items"), 1);
1500415009
ASSERT_EQ(http_calls_to_route(s, project, "deleteItem", "__route__DELETE__/items/{}"), 1);
15010+
/* A chain wrapped before the verb (prettier style) is the same client call */
15011+
ASSERT_EQ(http_calls_to_route(s, project, "updateItem", "__route__PUT__/items/{}"), 1);
15012+
ASSERT_EQ(http_calls_to_route(s, project, "updateItem", "__route__ANY__"), 0);
1500515013

1500615014
/* Assert no ANY twins */
1500715015
ASSERT_EQ(http_calls_to_route(s, project, "getItems", "__route__ANY__"), 0);

0 commit comments

Comments
 (0)