File tree 2 files changed +30
-4
lines changed
2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,26 @@ describe(readLogo, () => {
24
24
expect ( logo ) . toBeUndefined ( ) ;
25
25
} ) ;
26
26
27
+ it ( "resolves undefined when the found image is an All Contributors badge" , async ( ) => {
28
+ const logo = await readLogo ( ( ) =>
29
+ Promise . resolve (
30
+ `\n<img alt="All Contributors: 1" src="https://img.shields.io/badge/all_contributors-1-21bb42.svg" />` ,
31
+ ) ,
32
+ ) ;
33
+
34
+ expect ( logo ) . toBeUndefined ( ) ;
35
+ } ) ;
36
+
37
+ it ( "resolves undefined when the found image is a shields.io badge" , async ( ) => {
38
+ const logo = await readLogo ( ( ) =>
39
+ Promise . resolve (
40
+ `\n<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />` ,
41
+ ) ,
42
+ ) ;
43
+
44
+ expect ( logo ) . toBeUndefined ( ) ;
45
+ } ) ;
46
+
27
47
it ( "parses when found in an unquoted string" , async ( ) => {
28
48
const logo = await readLogo ( ( ) =>
29
49
Promise . resolve ( `
Original file line number Diff line number Diff line change @@ -7,19 +7,25 @@ export async function readLogo(getReadme: () => Promise<string>) {
7
7
return undefined ;
8
8
}
9
9
10
+ const alt =
11
+ / a l t = [ ' " ] ( .+ ) [ ' " ] \s * s r c = / . exec ( tag ) ?. [ 1 ] . split ( / [ ' " ] ? \s * \w + = / ) [ 0 ] ??
12
+ "Project logo" ;
13
+
14
+ if ( / A l l C o n t r i b u t o r s : \d + / . test ( alt ) ) {
15
+ return undefined ;
16
+ }
17
+
10
18
const src = / s r c \s * = ( .+ ) [ ' " / ] > /
11
19
. exec ( tag ) ?. [ 1 ]
12
20
?. split ( / \s * \w + = / ) [ 0 ]
13
21
. replaceAll ( / ^ [ ' " ] | [ ' " ] $ / g, "" ) ;
14
22
15
- if ( ! src ) {
23
+ if ( ! src || src . includes ( "//img.shields.io" ) ) {
16
24
return undefined ;
17
25
}
18
26
19
27
return {
20
- alt :
21
- / a l t = [ ' " ] ( .+ ) [ ' " ] \s * s r c = / . exec ( tag ) ?. [ 1 ] . split ( / [ ' " ] ? \s * \w + = / ) [ 0 ] ??
22
- "Project logo" ,
28
+ alt,
23
29
src,
24
30
...readLogoSizing ( src ) ,
25
31
} ;
You can’t perform that action at this time.
0 commit comments