Skip to content

Commit d9766ae

Browse files
committed
fix(pipeline): keep route properties that are not UTF-8
Review follow-up to the previous commit. Properties hold source text as its bytes, so a Latin-1 docstring stored beside route_path is not UTF-8. The strict yyjson parse rejected that whole object, so the route pass skipped rebuilding the handler's Route, where the old quote scan had rebuilt it. Parse with YYJSON_READ_ALLOW_INVALID_UNICODE, as internal/cbm/diagram.c does. Test: infrascan_decorator_route_metadata_survives_invalid_utf8 fails with the strict parse, and passes with this change and on 4cf4414. Signed-off-by: Petteri Ponsimaa <petterip@gmail.com>
1 parent 671bc49 commit d9766ae

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎src/pipeline/pass_route_nodes.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ static int ensure_one_decorator_route(cbm_gbuf_t *gb, const cbm_gbuf_node_t *fun
446446
return 0;
447447
}
448448

449-
yyjson_doc *doc = yyjson_read(func->properties_json, strlen(func->properties_json), 0);
449+
/* Properties hold source text as its bytes, which need not be UTF-8. */
450+
yyjson_doc *doc = yyjson_read(func->properties_json, strlen(func->properties_json),
451+
YYJSON_READ_ALLOW_INVALID_UNICODE);
450452
yyjson_val *root = yyjson_doc_get_root(doc);
451453
char path[CBM_SZ_256];
452454
char method[CBM_SZ_16] = "ANY";

‎tests/test_infrascan.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,31 @@ TEST(infrascan_decorator_route_metadata_rejects_malformed_values) {
620620
PASS();
621621
}
622622

623+
/* Properties hold source text as its bytes, which need not be UTF-8: a
624+
* Latin-1 docstring beside the route metadata, or a Latin-1 route path. The
625+
* Route extraction emits for them must come back from the stored metadata too,
626+
* as it did before the metadata was parsed. */
627+
TEST(infrascan_decorator_route_metadata_survives_invalid_utf8) {
628+
cbm_gbuf_t *gb = cbm_gbuf_new("test", "/tmp/cbm_infrascan_route_latin1");
629+
ASSERT_NOT_NULL(gb);
630+
ASSERT_GT(cbm_gbuf_upsert_node(gb, "Function", "doc", "test.doc", "views.py", 1, 1,
631+
"{\"docstring\":\"caf\xe9\",\"route_path\":\"/doc\","
632+
"\"route_method\":\"GET\"}"),
633+
0);
634+
ASSERT_GT(cbm_gbuf_upsert_node(gb, "Function", "GET", "test.app.caf\xe9.route.GET",
635+
"app/caf\xe9/route.ts", 1, 1,
636+
"{\"route_path\":\"/caf\xe9\",\"route_method\":\"GET\"}"),
637+
0);
638+
cbm_pipeline_create_route_nodes(gb);
639+
const cbm_gbuf_node_t *doc_route = cbm_gbuf_find_by_qn(gb, "__route__GET__/doc");
640+
const cbm_gbuf_node_t *dir_route = cbm_gbuf_find_by_qn(gb, "__route__GET__/caf\xe9");
641+
bool both = doc_route && dir_route && strcmp(dir_route->name, "/caf\xe9") == 0 &&
642+
cbm_gbuf_edge_count_by_type(gb, "HANDLES") == 2;
643+
cbm_gbuf_free(gb);
644+
ASSERT_TRUE(both);
645+
PASS();
646+
}
647+
623648
/* FD16: a route's DATA_FLOWS were built from the first 64 callers and the first 32 infra handlers
624649
* in edge-insertion order (parallel worker interleaving), so the flow set changed between two
625650
* indexes of the same tree and every caller past the 64th lost its flow. */
@@ -794,6 +819,7 @@ SUITE(infrascan) {
794819
RUN_TEST(infrascan_http_calls_join_matching_handler_route);
795820
RUN_TEST(infrascan_decorator_route_metadata_keeps_its_escapes);
796821
RUN_TEST(infrascan_decorator_route_metadata_rejects_malformed_values);
822+
RUN_TEST(infrascan_decorator_route_metadata_survives_invalid_utf8);
797823
RUN_TEST(infrascan_handles_properties_hold_a_long_handler_qn);
798824
RUN_TEST(infrascan_route_properties_escape_the_method);
799825
RUN_TEST(infrascan_sveltekit_handles_properties_escape_the_handler_qn);

0 commit comments

Comments
 (0)