Skip to content

Commit ff3ebd4

Browse files
committed
Fix remote config UTF-8 decoding
1 parent 3ea37a4 commit ff3ebd4

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/config/file.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,67 @@ test("getConfigFileInput ignores repository property value when FF is off", asyn
108108
.passes(t.is, undefined);
109109
});
110110

111+
for (const { name, contents } of [
112+
...["Security", "Sécurité", "日本語", "🛡️"].map((configName) => ({
113+
name: configName,
114+
contents: `name: ${configName}
115+
paths:
116+
- "src/${configName}"
117+
paths-ignore:
118+
- "generated/${configName}"
119+
`,
120+
})),
121+
{
122+
name: "Café",
123+
contents: `name: "Caf\\u00e9"
124+
paths:
125+
- "src/Caf\\u00e9"
126+
paths-ignore:
127+
- "generated/Caf\\u00e9"
128+
`,
129+
},
130+
]) {
131+
test.serial(
132+
`getRemoteConfig preserves UTF-8 configuration: ${name}`,
133+
async (t) => {
134+
const configFile = "octo-org/codeql-config/config.yml@main";
135+
const config = {
136+
name,
137+
paths: [`src/${name}`],
138+
"paths-ignore": [`generated/${name}`],
139+
};
140+
const client = github.getOctokit("123");
141+
const response = {
142+
data: {
143+
content: Buffer.from(contents, "utf8").toString("base64"),
144+
encoding: "base64",
145+
},
146+
};
147+
const getContent = sinon
148+
.stub(client.rest.repos, "getContent")
149+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
150+
.resolves(response as any);
151+
sinon.stub(api, "getApiClientWithExternalAuth").returns(client);
152+
153+
for (const features of [[], [Feature.ValidateDbConfig]]) {
154+
await callee(getRemoteConfig)
155+
.withFeatures(features)
156+
.withArgs(configFile, SAMPLE_DOTCOM_API_DETAILS)
157+
.passes(t.deepEqual, config);
158+
}
159+
160+
t.assert(
161+
getContent.alwaysCalledWithExactly({
162+
owner: "octo-org",
163+
repo: "codeql-config",
164+
path: "config.yml",
165+
ref: "main",
166+
}),
167+
);
168+
},
169+
);
170+
}
171+
111172
test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => {
112173
const client = github.getOctokit("123");
113174
const response = {

‎src/config/file.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function getRemoteConfig(
131131
return parseUserConfig(
132132
actionState.logger,
133133
configFile,
134-
Buffer.from(fileContents, "base64").toString("binary"),
134+
Buffer.from(fileContents, "base64").toString("utf8"),
135135
validateConfig,
136136
);
137137
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed remote configuration files corrupting Unicode names and paths or failing to parse when they contain non-ASCII characters.

0 commit comments

Comments
 (0)