fix(slack): land #26878 allowlist channel ID case-insensitive match (thanks @lbo728)
Land contributor PR #26878 from @lbo728; include changelog credit and regression tests. Co-authored-by: lbo728 <extreme0728@gmail.com>
This commit is contained in:
@@ -96,8 +96,16 @@ export function resolveSlackChannelConfig(params: {
|
||||
const keys = Object.keys(entries);
|
||||
const normalizedName = channelName ? normalizeSlackSlug(channelName) : "";
|
||||
const directName = channelName ? channelName.trim() : "";
|
||||
// Slack always delivers channel IDs in uppercase (e.g. C0ABC12345) but
|
||||
// operators commonly write them in lowercase in their config. Add both
|
||||
// case variants so the lookup is case-insensitive without requiring a full
|
||||
// entry-scan. buildChannelKeyCandidates deduplicates identical keys.
|
||||
const channelIdLower = channelId.toLowerCase();
|
||||
const channelIdUpper = channelId.toUpperCase();
|
||||
const candidates = buildChannelKeyCandidates(
|
||||
channelId,
|
||||
channelIdLower !== channelId ? channelIdLower : undefined,
|
||||
channelIdUpper !== channelId ? channelIdUpper : undefined,
|
||||
channelName ? `#${directName}` : undefined,
|
||||
directName,
|
||||
normalizedName,
|
||||
|
||||
@@ -60,6 +60,27 @@ describe("resolveSlackChannelConfig", () => {
|
||||
matchSource: "direct",
|
||||
});
|
||||
});
|
||||
|
||||
it("matches channel config key stored in lowercase when Slack delivers uppercase channel ID", () => {
|
||||
// Slack always delivers channel IDs in uppercase (e.g. C0ABC12345).
|
||||
// Users commonly copy them in lowercase from docs or older CLI output.
|
||||
const res = resolveSlackChannelConfig({
|
||||
channelId: "C0ABC12345",
|
||||
channels: { c0abc12345: { allow: true, requireMention: false } },
|
||||
defaultRequireMention: true,
|
||||
});
|
||||
expect(res).toMatchObject({ allowed: true, requireMention: false });
|
||||
});
|
||||
|
||||
it("matches channel config key stored in uppercase when user types lowercase channel ID", () => {
|
||||
// Defensive: also handle the inverse direction.
|
||||
const res = resolveSlackChannelConfig({
|
||||
channelId: "c0abc12345",
|
||||
channels: { C0ABC12345: { allow: true, requireMention: false } },
|
||||
defaultRequireMention: true,
|
||||
});
|
||||
expect(res).toMatchObject({ allowed: true, requireMention: false });
|
||||
});
|
||||
});
|
||||
|
||||
const baseParams = () => ({
|
||||
|
||||
Reference in New Issue
Block a user