Skip to content

Commit a76600d

Browse files
committed
revert(extract): drop template-URL constant resolution now done by the URL fold
Since 77bc492 (merged with DeusData#2513), the extractor folds a template URL over a module string constant before the template flattener runs, so fetch(`${BASE_URL}/v1/payments`) with a literal BASE_URL already yields an HTTP_CALLS edge to the /v1/payments route (DeusData#2540). Resolving the constant a second time inside cbm_template_string_text is no longer needed, so the production part of this change is dropped and the helper keeps its original signature. The pipeline regression test from this PR stays: it fails on main before DeusData#2513 (no HTTP_CALLS edge) and passes on current main. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 21c224f commit a76600d

4 files changed

Lines changed: 21 additions & 41 deletions

File tree

‎internal/cbm/extract_calls.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,9 +2192,9 @@ static void extract_call_args(CBMExtractCtx *ctx, TSNode args, CBMCall *call) {
21922192
if (is_string_like(ak) && ca->expr) {
21932193
ca->value = strip_quotes(ctx->arena, ca->expr);
21942194
} else if (strcmp(ak, "template_string") == 0) {
2195-
/* Resolve known constants; dynamic substitutions keep the route placeholder. */
2196-
ca->value = cbm_template_string_text(ctx->arena, arg_node, ctx->source,
2197-
&ctx->string_constants);
2195+
/* Flattened {} form so downstream url-arg detection joins the
2196+
* canonical server route shape (issue #1006/#1009). */
2197+
ca->value = cbm_template_string_text(ctx->arena, arg_node, ctx->source);
21982198
} else if (strcmp(ak, "identifier") == 0 && ca->expr) {
21992199
ca->value = lookup_string_constant(ctx, ca->expr);
22002200
} else if (strcmp(ak, "object") == 0) {
@@ -2259,8 +2259,7 @@ static bool is_queue_topic_field(const char *key) {
22592259
static const char *extract_string_value(CBMExtractCtx *ctx, TSNode val_node) {
22602260
const char *vk = ts_node_type(val_node);
22612261
if (strcmp(vk, "template_string") == 0) {
2262-
return cbm_template_string_text(ctx->arena, val_node, ctx->source,
2263-
&ctx->string_constants);
2262+
return cbm_template_string_text(ctx->arena, val_node, ctx->source);
22642263
}
22652264
if (is_string_like(vk)) {
22662265
char *text = cbm_node_text(ctx->arena, val_node, ctx->source);
@@ -2435,10 +2434,10 @@ static TSNode swift_unwrap_url_constructor(CBMExtractCtx *ctx, TSNode arg) {
24352434
}
24362435

24372436
static const char *extract_positional_url(CBMExtractCtx *ctx, TSNode arg, const char *ak) {
2438-
/* Resolve constants while keeping dynamic route parts in canonical form. */
2437+
/* JS/TS template literals: `/things/${id}` normalizes to "/things/{}" so the
2438+
* client URL joins the server route's canonical placeholder (issue #1006). */
24392439
if (strcmp(ak, "template_string") == 0) {
2440-
const char *flat = cbm_template_string_text(ctx->arena, arg, ctx->source,
2441-
&ctx->string_constants);
2440+
const char *flat = cbm_template_string_text(ctx->arena, arg, ctx->source);
24422441
if (flat) {
24432442
return strip_and_validate_string_arg(ctx->arena, (char *)flat);
24442443
}

‎internal/cbm/extract_unified.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ static void handle_string_constants(CBMExtractCtx *ctx, TSNode node, const WalkS
12121212
const char *value_kind = ts_node_type(value_node);
12131213
const char *flat_value = NULL;
12141214
if (strcmp(value_kind, "template_string") == 0) {
1215-
flat_value = cbm_template_string_text(ctx->arena, value_node, ctx->source, NULL);
1215+
flat_value = cbm_template_string_text(ctx->arena, value_node, ctx->source);
12161216
if (!flat_value) {
12171217
return;
12181218
}
@@ -1263,7 +1263,7 @@ static void handle_string_refs(CBMExtractCtx *ctx, TSNode node, const WalkState
12631263
* template strings become string_refs with the canonical placeholder shape
12641264
* shared with server route paths (issue #1006). */
12651265
if (strcmp(kind, "template_string") == 0) {
1266-
const char *flat = cbm_template_string_text(ctx->arena, node, ctx->source, NULL);
1266+
const char *flat = cbm_template_string_text(ctx->arena, node, ctx->source);
12671267
if (!flat) {
12681268
return;
12691269
}

‎internal/cbm/helpers.c‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,10 +1803,13 @@ int cbm_classify_string(const char *str, int len) {
18031803
return NOT_FOUND;
18041804
}
18051805

1806-
/* Flatten a JS/TS template string, resolving known string constants and
1807-
* replacing other substitutions with the route placeholder. */
1808-
const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *source,
1809-
const CBMStringConstantMap *string_constants) {
1806+
/* Flatten a JS/TS `template_string` node into plain text (issue #1006).
1807+
* String fragments are kept verbatim; each ${...} substitution becomes the
1808+
* "{}" placeholder so client URLs built from template literals share the
1809+
* canonical parameter shape of server-side route paths
1810+
* (`/things/${id}/x` -> "/things/{}/x"). Returns NULL when the node yields
1811+
* no text or exceeds the route-sized buffer. */
1812+
const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *source) {
18101813
enum { TPL_BUF = 512 };
18111814
char buf[TPL_BUF];
18121815
size_t pos = 0;
@@ -1826,29 +1829,6 @@ const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *sourc
18261829
memcpy(buf + pos, frag, fl);
18271830
pos += fl;
18281831
} else if (strcmp(k, "template_substitution") == 0) {
1829-
const char *resolved = NULL;
1830-
TSNode expr = ts_node_named_child(c, 0);
1831-
if (string_constants && !ts_node_is_null(expr) &&
1832-
strcmp(ts_node_type(expr), "identifier") == 0) {
1833-
char *name = cbm_node_text(a, expr, source);
1834-
for (int j = 0; name && j < string_constants->count; j++) {
1835-
if (!string_constants->is_url_builder[j] && string_constants->names[j] &&
1836-
string_constants->values[j] &&
1837-
strcmp(string_constants->names[j], name) == 0) {
1838-
resolved = string_constants->values[j];
1839-
break;
1840-
}
1841-
}
1842-
}
1843-
if (resolved) {
1844-
size_t rl = strlen(resolved);
1845-
if (pos + rl >= TPL_BUF) {
1846-
return NULL;
1847-
}
1848-
memcpy(buf + pos, resolved, rl);
1849-
pos += rl;
1850-
continue;
1851-
}
18521832
if (pos + PAIR_LEN >= TPL_BUF) {
18531833
return NULL;
18541834
}

‎internal/cbm/helpers.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,10 @@ char *cbm_fqn_compute_source_lang(CBMArena *a, const char *project, const char *
253253
// Folder QN: project.dir_parts
254254
char *cbm_fqn_folder(CBMArena *a, const char *project, const char *rel_dir);
255255

256-
/* Flatten JS/TS template strings for URL extraction. Known string constants
257-
* resolve; other substitutions become "{}". NULL when empty/oversized. */
258-
const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *source,
259-
const CBMStringConstantMap *string_constants);
256+
/* Flatten a JS/TS `template_string` node into plain text: string fragments are
257+
* kept verbatim and each ${...} substitution becomes the "{}" placeholder, so
258+
* client-side URLs built from template literals share the canonical parameter
259+
* shape that server-side route paths already use. NULL when empty/oversized. */
260+
const char *cbm_template_string_text(CBMArena *a, TSNode node, const char *source);
260261

261262
#endif // CBM_HELPERS_H

0 commit comments

Comments
 (0)