Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Compact document",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
10 changes: 9 additions & 1 deletion packages/extensions/openapi-to-typespec/src/utils/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
const wrapped = lineWrap(doc || defaultValue);

for (let i = 0; i < wrapped.length; i++) {
if (wrapped[i].includes("@") || wrapped[i].includes("*/")) {
if (wrapped[i].includes("@")) {
wrapped[i] = wrapped[i].replace(/@/g, "\\@");

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in L20

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is what the codeql is warning you about. I think it tells you that you won't escape this correctly

\@

becomes

\\@

but I think for how doc comments are parsed its a false positive.

you might also be able to replace to .replaceAll("@", "\\@") instead of using regex and it might not flag

}

if (wrapped[i].includes("*/")) {
if (wrapped.length === 1) {
return `@doc("${wrapped[0].replace(/\\/g, "\\\\").replace(/"/g, '\\"')}")`;
}
return `@doc("""\n${wrapped.join("\n").replace(/\\/g, "\\\\").replace(/"/g, '\\"')}\n""")`;
}
}

if (wrapped.length === 1) {
return `/** ${wrapped[0]} */`;
}

return `/**\n* ${wrapped.join("\n* ")}\n*/`;
}

Expand Down
Loading
Loading