From 02bac03162280236ef7a33993358cb7dcff443d1 Mon Sep 17 00:00:00 2001 From: Florent Revest Date: Wed, 21 Jan 2026 15:38:10 +0100 Subject: tools/clang/json: escape strings properly When preparing a codesearch index, I encountered errors which I narrowed down to lines like the following in the json output of codesearch: "type": "void (void __attribute__((btf_type_tag("user")))*, const void *, size_t, size_t)", After this change, the line gets formatted like this: "type": "void (void __attribute__((btf_type_tag(\"user\")))*, const void *, size_t, size_t)", This fixes the errors I encountered --- .../testdata/query-def-source-quote-type | 7 +++ pkg/codesearch/testdata/query-file-index-source | 1 + pkg/codesearch/testdata/source0.c | 4 ++ pkg/codesearch/testdata/source0.c.json | 51 +++++++++++++--------- 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 pkg/codesearch/testdata/query-def-source-quote-type (limited to 'pkg/codesearch/testdata') diff --git a/pkg/codesearch/testdata/query-def-source-quote-type b/pkg/codesearch/testdata/query-def-source-quote-type new file mode 100644 index 000000000..cc0f4721a --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-quote-type @@ -0,0 +1,7 @@ +def-source source0.c function_with_quotes_in_type yes + +function function_with_quotes_in_type is defined in source0.c: + + 35: void function_with_quotes_in_type(void __attribute__((btf_type_tag("user"))) *) + 36: { + 37: } diff --git a/pkg/codesearch/testdata/query-file-index-source b/pkg/codesearch/testdata/query-file-index-source index af52513b7..edfe4616f 100644 --- a/pkg/codesearch/testdata/query-file-index-source +++ b/pkg/codesearch/testdata/query-file-index-source @@ -5,5 +5,6 @@ file source0.c defines the following entities: function close function func_accepting_a_struct function function_with_comment_in_header +function function_with_quotes_in_type function open struct struct_in_c_file diff --git a/pkg/codesearch/testdata/source0.c b/pkg/codesearch/testdata/source0.c index 5ac117cab..e5b47841b 100644 --- a/pkg/codesearch/testdata/source0.c +++ b/pkg/codesearch/testdata/source0.c @@ -31,3 +31,7 @@ int func_accepting_a_struct(struct some_struct* p) return ((some_struct_t*)p)->x + ((union some_union*)p)->x; } + +void function_with_quotes_in_type(void __attribute__((btf_type_tag("user"))) *) +{ +} diff --git a/pkg/codesearch/testdata/source0.c.json b/pkg/codesearch/testdata/source0.c.json index c2c2de3e4..5d347ae1b 100644 --- a/pkg/codesearch/testdata/source0.c.json +++ b/pkg/codesearch/testdata/source0.c.json @@ -1,15 +1,5 @@ { "definitions": [ - { - "name": "some_enum", - "kind": "enum", - "body": { - "file": "source0.h", - "start_line": 45, - "end_line": 48 - }, - "comment": {} - }, { "name": "close", "type": "int ()", @@ -89,6 +79,17 @@ } ] }, + { + "name": "function_with_quotes_in_type", + "type": "void (void __attribute__((btf_type_tag(\"user\")))*)", + "kind": "function", + "body": { + "file": "source0.c", + "start_line": 35, + "end_line": 37 + }, + "comment": {} + }, { "name": "open", "type": "int ()", @@ -148,6 +149,26 @@ }, "comment": {} }, + { + "name": "some_union", + "kind": "union", + "body": { + "file": "source0.h", + "start_line": 40, + "end_line": 43 + }, + "comment": {} + }, + { + "name": "some_enum", + "kind": "enum", + "body": { + "file": "source0.h", + "start_line": 45, + "end_line": 48 + }, + "comment": {} + }, { "name": "another_struct_t", "kind": "typedef", @@ -187,16 +208,6 @@ "end_line": 34 }, "comment": {} - }, - { - "name": "some_union", - "kind": "union", - "body": { - "file": "source0.h", - "start_line": 40, - "end_line": 43 - }, - "comment": {} } ] } \ No newline at end of file -- cgit mrf-deployment