diff --git a/src/options/readLogo.test.ts b/src/options/readLogo.test.ts index 07a70e8f2..e1bf702d7 100644 --- a/src/options/readLogo.test.ts +++ b/src/options/readLogo.test.ts @@ -24,6 +24,26 @@ describe(readLogo, () => { expect(logo).toBeUndefined(); }); + it("resolves undefined when the found image is an All Contributors badge", async () => { + const logo = await readLogo(() => + Promise.resolve( + `\nAll Contributors: 1`, + ), + ); + + expect(logo).toBeUndefined(); + }); + + it("resolves undefined when the found image is a shields.io badge", async () => { + const logo = await readLogo(() => + Promise.resolve( + `\nTypeScript: Strict`, + ), + ); + + expect(logo).toBeUndefined(); + }); + it("parses when found in an unquoted string", async () => { const logo = await readLogo(() => Promise.resolve(` diff --git a/src/options/readLogo.ts b/src/options/readLogo.ts index 750ee910d..3abdbf19e 100644 --- a/src/options/readLogo.ts +++ b/src/options/readLogo.ts @@ -7,19 +7,25 @@ export async function readLogo(getReadme: () => Promise) { return undefined; } + const alt = + /alt=['"](.+)['"]\s*src=/.exec(tag)?.[1].split(/['"]?\s*\w+=/)[0] ?? + "Project logo"; + + if (/All Contributors: \d+/.test(alt)) { + return undefined; + } + const src = /src\s*=(.+)['"/]>/ .exec(tag)?.[1] ?.split(/\s*\w+=/)[0] .replaceAll(/^['"]|['"]$/g, ""); - if (!src) { + if (!src || src.includes("//img.shields.io")) { return undefined; } return { - alt: - /alt=['"](.+)['"]\s*src=/.exec(tag)?.[1].split(/['"]?\s*\w+=/)[0] ?? - "Project logo", + alt, src, ...readLogoSizing(src), };