File tree Expand file tree Collapse file tree 5 files changed +78
-52
lines changed Expand file tree Collapse file tree 5 files changed +78
-52
lines changed Original file line number Diff line number Diff line change 1+ exports['escape when the value is not empty 1'] = {
2+ "title": "<script src=‘http://127.0.0.1:8080/malware.js’></script>"
3+ }
4+
Original file line number Diff line number Diff line change @@ -28,6 +28,34 @@ it('url is required', async () => {
2828 }
2929} )
3030
31+ it ( 'escape is enabled by default' , async ( ) => {
32+ const html = `
33+ <!doctype html>
34+ <html xmlns:og="http://ogp.me/ns#" lang="en">
35+
36+ <head>
37+ <meta charset="utf8">
38+ <title>metascraper</title>
39+ <meta property="og:description" content="The HR startups go to war.">
40+ <meta property="og:image" content="image">
41+ <meta property="og:title" content="<script src='http://127.0.0.1:8080/malware.js'></script>">
42+ <meta property="og:type" content="article">
43+ <meta property="og:url" content="http://127.0.0.1:8080">
44+ </head>
45+
46+ <body>
47+ </body>
48+ </html>
49+ `
50+
51+ const metadata = await metascraper ( {
52+ html : html ,
53+ url : 'http://127.0.0.1:8080'
54+ } )
55+
56+ should ( metadata . title ) . be . equal ( '<script src=‘http://127.0.0.1:8080/malware.js’></script>' )
57+ } )
58+
3159it ( 'load extra rules' , async ( ) => {
3260 const url = 'https://microlink.io'
3361
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const metascraper = require ( 'metascraper' ) ( [ require ( 'metascraper-title' ) ( ) ] )
4+ const snapshot = require ( 'snap-shot' )
5+ const should = require ( 'should' )
6+
7+ const html = `
8+ <!doctype html>
9+ <html xmlns:og="http://ogp.me/ns#" lang="en">
10+
11+ <head>
12+ <meta charset="utf8">
13+ <title>metascraper</title>
14+ <meta property="og:description" content="The HR startups go to war.">
15+ <meta property="og:image" content="image">
16+ <meta property="og:title" content="<script src='http://127.0.0.1:8080/malware.js'></script>">
17+ <meta property="og:type" content="article">
18+ <meta property="og:url" content="http://127.0.0.1:8080">
19+ </head>
20+
21+ <body>
22+ </body>
23+ </html>
24+ `
25+
26+ describe ( 'xss' , ( ) => {
27+ it ( 'explicitily disable escape' , async ( ) => {
28+ const metadata = await metascraper ( {
29+ html : html ,
30+ url : 'http://127.0.0.1:8080' ,
31+ escape : false
32+ } )
33+
34+ should ( metadata . title ) . be . equal ( '<script src=‘http://127.0.0.1:8080/malware.js’></script>' )
35+ } )
36+
37+ it ( 'escape when the value is not empty' , async ( ) => {
38+ const metadata = await metascraper ( {
39+ html : html ,
40+ url : 'http://127.0.0.1:8080' ,
41+ escape : true
42+ } )
43+
44+ snapshot ( metadata )
45+ } )
46+ } )
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments