robots-parser 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +12 -0
- package/Robots.js +13 -4
- package/package.json +1 -1
- package/test/Robots.js +61 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Version 3.1.2
|
|
4
|
+
|
|
5
|
+
- Fixed bug with non-encoded special characters in `allow` and `disallow` paths, and now handles non-encoded spaces inside paths.
|
|
6
|
+
– Thanks to @bardrop for reporting and fixing.
|
|
7
|
+
|
|
8
|
+
## Version 3.1.1
|
|
9
|
+
|
|
10
|
+
- Fixed bug from 3.1.0 with sitemap, crawl-delay, host and unknown directives not terminating groups.
|
|
11
|
+
– Thanks to @bardrop for reporting and fixing.
|
|
12
|
+
|
|
3
13
|
## Version 3.1.0
|
|
4
14
|
|
|
5
15
|
- Updated README to point to RFC 9309 instead of the draft specification.
|
|
6
16
|
– Thanks to @joepie91 for reporting.
|
|
17
|
+
- Fixed CommonJS export type in typescript definitions.
|
|
18
|
+
– Thanks to @markedwards for fixing.
|
|
7
19
|
- Added `isExplicitlyDisallowed()` method.
|
|
8
20
|
– Thanks to @AuDigent for implementing.
|
|
9
21
|
- Fixed grouping to match RFC 9309 by not treating non-standard directives like crawl-delay as terminating a group.
|
package/README.md
CHANGED
|
@@ -112,10 +112,22 @@ Returns the preferred host name specified by the `host:` directive or null if th
|
|
|
112
112
|
|
|
113
113
|
# Changes
|
|
114
114
|
|
|
115
|
+
## Version 3.1.2
|
|
116
|
+
|
|
117
|
+
- Fixed bug with non-encoded special characters in `allow` and `disallow` paths, and now handles non-encoded spaces inside paths.
|
|
118
|
+
– Thanks to @bardrop for reporting and fixing.
|
|
119
|
+
|
|
120
|
+
## Version 3.1.1
|
|
121
|
+
|
|
122
|
+
- Fixed bug from 3.1.0 with sitemap, crawl-delay, host and unknown directives not terminating groups.
|
|
123
|
+
– Thanks to @bardrop for reporting and fixing.
|
|
124
|
+
|
|
115
125
|
## Version 3.1.0
|
|
116
126
|
|
|
117
127
|
- Updated README to point to RFC 9309 instead of the draft specification.
|
|
118
128
|
– Thanks to @joepie91 for reporting.
|
|
129
|
+
- Fixed CommonJS export type in typescript definitions.
|
|
130
|
+
– Thanks to @markedwards for fixing.
|
|
119
131
|
- Added `isExplicitlyDisallowed()` method.
|
|
120
132
|
– Thanks to @AuDigent for implementing.
|
|
121
133
|
- Fixed grouping to match RFC 9309 by not treating non-standard directives like crawl-delay as terminating a group.
|
package/Robots.js
CHANGED
|
@@ -76,7 +76,8 @@ function formatUserAgent(userAgent) {
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Normalises the URL encoding of a path by encoding
|
|
79
|
-
* unicode characters
|
|
79
|
+
* unicode characters and ASCII characters that are not
|
|
80
|
+
* allowed in a URL.
|
|
80
81
|
*
|
|
81
82
|
* @param {string} path
|
|
82
83
|
* @return {string}
|
|
@@ -84,8 +85,10 @@ function formatUserAgent(userAgent) {
|
|
|
84
85
|
*/
|
|
85
86
|
function normaliseEncoding(path) {
|
|
86
87
|
try {
|
|
87
|
-
// Encode any non-ASCII chars
|
|
88
|
-
|
|
88
|
+
// Encode any non-ASCII chars and the ASCII chars that are not allowed
|
|
89
|
+
// in a URL (the URL parser encodes most of these in paths, so the
|
|
90
|
+
// patterns must be encoded the same way to match)
|
|
91
|
+
return safeDecodeURI(path).replace(/[^\x00-\x7F]|[\x00-\x20"<>\\^`{|}\x7F]/gu, (char) => {
|
|
89
92
|
return encodeURIComponent(char).toUpperCase();
|
|
90
93
|
});
|
|
91
94
|
} catch (e) {
|
|
@@ -402,7 +405,13 @@ function parseRobots(contents, robots) {
|
|
|
402
405
|
break;
|
|
403
406
|
}
|
|
404
407
|
|
|
405
|
-
|
|
408
|
+
// Other records (sitemap, crawl-delay, host, unknown) must not change
|
|
409
|
+
// the grouping: only a rule ends the user-agent lines of a group
|
|
410
|
+
if (rule === 'user-agent') {
|
|
411
|
+
isGroupTermination = false;
|
|
412
|
+
} else if (rule === 'allow' || rule === 'disallow') {
|
|
413
|
+
isGroupTermination = true;
|
|
414
|
+
}
|
|
406
415
|
isNoneStandardGroupTermination = rule !== 'user-agent';
|
|
407
416
|
}
|
|
408
417
|
}
|
package/package.json
CHANGED
package/test/Robots.js
CHANGED
|
@@ -536,6 +536,36 @@ describe('Robots', function () {
|
|
|
536
536
|
testRobots('http://www.example.com/robots.txt', contents, allowed, disallowed);
|
|
537
537
|
});
|
|
538
538
|
|
|
539
|
+
it('should match characters the URL parser percent-encodes', function () {
|
|
540
|
+
var contents = [
|
|
541
|
+
'User-agent: *',
|
|
542
|
+
'Disallow: /a b',
|
|
543
|
+
'Disallow: /*"',
|
|
544
|
+
'Disallow: /*{',
|
|
545
|
+
'Disallow: /*^',
|
|
546
|
+
'Disallow: /c|d',
|
|
547
|
+
'Disallow: /e%7Cf'
|
|
548
|
+
].join('\n');
|
|
549
|
+
|
|
550
|
+
var allowed = [
|
|
551
|
+
'http://www.example.com/ab',
|
|
552
|
+
'http://www.example.com/c'
|
|
553
|
+
];
|
|
554
|
+
|
|
555
|
+
var disallowed = [
|
|
556
|
+
'http://www.example.com/a b',
|
|
557
|
+
'http://www.example.com/a%20b',
|
|
558
|
+
'http://www.example.com/x"',
|
|
559
|
+
'http://www.example.com/x{y}',
|
|
560
|
+
'http://www.example.com/x^y',
|
|
561
|
+
'http://www.example.com/c|d',
|
|
562
|
+
'http://www.example.com/c%7Cd',
|
|
563
|
+
'http://www.example.com/e|f'
|
|
564
|
+
];
|
|
565
|
+
|
|
566
|
+
testRobots('http://www.example.com/robots.txt', contents, allowed, disallowed);
|
|
567
|
+
});
|
|
568
|
+
|
|
539
569
|
it('should handle lone high / low surrogates', function () {
|
|
540
570
|
var contents = [
|
|
541
571
|
'User-agent: *',
|
|
@@ -1257,6 +1287,37 @@ describe('Robots', function () {
|
|
|
1257
1287
|
testRobots('https://www.example.com/robots.txt', contents, allowed, disallowed);
|
|
1258
1288
|
});
|
|
1259
1289
|
|
|
1290
|
+
it('should start a new group after rules even if other records follow them', function () {
|
|
1291
|
+
['Sitemap: http://www.example.com/sitemap.xml', 'Crawl-delay: 1', 'Host: www.example.com', 'Foo: bar'].forEach(function (record) {
|
|
1292
|
+
var contents = [
|
|
1293
|
+
'User-agent: a',
|
|
1294
|
+
'Allow: /fish',
|
|
1295
|
+
record,
|
|
1296
|
+
'User-agent: b',
|
|
1297
|
+
'Disallow: /'
|
|
1298
|
+
].join('\n');
|
|
1299
|
+
|
|
1300
|
+
var robots = robotsParser('http://www.example.com/robots.txt', contents);
|
|
1301
|
+
|
|
1302
|
+
expect(robots.isAllowed('http://www.example.com/test.html', 'a'), record).to.equal(true);
|
|
1303
|
+
expect(robots.isAllowed('http://www.example.com/test.html', 'b'), record).to.equal(false);
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1307
|
+
it('should not end a group of user-agent lines on other records', function () {
|
|
1308
|
+
var contents = [
|
|
1309
|
+
'User-agent: a',
|
|
1310
|
+
'Sitemap: http://www.example.com/sitemap.xml',
|
|
1311
|
+
'User-agent: b',
|
|
1312
|
+
'Disallow: /'
|
|
1313
|
+
].join('\n');
|
|
1314
|
+
|
|
1315
|
+
var robots = robotsParser('http://www.example.com/robots.txt', contents);
|
|
1316
|
+
|
|
1317
|
+
expect(robots.isAllowed('http://www.example.com/test.html', 'a')).to.equal(false);
|
|
1318
|
+
expect(robots.isAllowed('http://www.example.com/test.html', 'b')).to.equal(false);
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1260
1321
|
it('should pass rfc9309-test-vectors.json tests', function () {
|
|
1261
1322
|
const file = path.resolve(__dirname,'./rfc9309-test-vectors.json')
|
|
1262
1323
|
const testVectors = JSON.parse(fs.readFileSync(file, 'utf8'));
|