File tree 3 files changed +31
-0
lines changed
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const linksAttr = {
9
9
icon : [ 'command' ] ,
10
10
longdesc : [ 'frame' , 'iframe' ] ,
11
11
manifest : [ 'html' ] ,
12
+ content : [ 'meta' ] ,
12
13
poster : [ 'video' ] ,
13
14
pluginspage : [ 'embed' ] ,
14
15
pluginurl : [ 'embed' ] ,
@@ -56,6 +57,17 @@ export function getLinks(source: string, baseUrl: string): ParsedUrl[] {
56
57
) {
57
58
return ;
58
59
}
60
+
61
+ // Only for <meta content=""> tags, only validate the url if
62
+ // the content actually looks like a url
63
+ if ( element . tagName === 'meta' && element . attribs [ 'content' ] ) {
64
+ try {
65
+ new URL ( element . attribs [ 'content' ] ) ;
66
+ } catch ( e ) {
67
+ return ;
68
+ }
69
+ }
70
+
59
71
for ( const v of values ) {
60
72
if ( v ) {
61
73
const link = parseLink ( v , realBaseUrl ) ;
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < head >
3
+ < meta name ="twitter:card " content ="summary "> </ meta >
4
+ < meta name ="twitter:creator " content ="@justinbeckwith " />
5
+ < meta name ="twitter:site " content ="@justinbeckwith " />
6
+ < meta property ="og:url " content ="http://fake.local/ " />
7
+ < meta property ="og:title " content ="A Twitter for My Sister " />
8
+ < meta property ="og:description " content ="In the early days, Twitter grew so quickly that it was almost impossible to add new features because engineers spent their time trying to keep the rocket ship from stalling. " />
9
+ < meta property ="og:image " content ="http://fake.local " />
10
+ </ head >
11
+ </ html >
Original file line number Diff line number Diff line change @@ -445,4 +445,12 @@ describe('linkinator', () => {
445
445
const err = results . links [ 0 ] . failureDetails ! [ 0 ] as Error ;
446
446
assert . ok ( / N o c k : D i s a l l o w e d n e t c o n n e c t f o r / . test ( err . message ) ) ;
447
447
} ) ;
448
+
449
+ it ( 'should scan links in <meta content="URL"> tags' , async ( ) => {
450
+ const scope = nock ( 'http://fake.local' ) . head ( '/' ) . reply ( 200 ) ;
451
+ const results = await check ( { path : 'test/fixtures/twittercard' } ) ;
452
+ assert . ok ( results . passed ) ;
453
+ scope . done ( ) ;
454
+ assert . strictEqual ( results . links . length , 2 ) ;
455
+ } ) ;
448
456
} ) ;
You can’t perform that action at this time.
0 commit comments