robots-parser 3.1.0 → 3.1.1

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 CHANGED
@@ -1,9 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 3.1.1
4
+
5
+ - Fixed bug from 3.1.0 with sitemap, crawl-delay, host and unknown directives not terminating groups.
6
+ – Thanks to @bardrop for reporting and fixing.
7
+
3
8
  ## Version 3.1.0
4
9
 
5
10
  - Updated README to point to RFC 9309 instead of the draft specification.
6
11
  – Thanks to @joepie91 for reporting.
12
+ - Fixed CommonJS export type in typescript definitions.
13
+ – Thanks to @markedwards for fixing.
7
14
  - Added `isExplicitlyDisallowed()` method.
8
15
  – Thanks to @AuDigent for implementing.
9
16
  - 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,17 @@ 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.1
116
+
117
+ - Fixed bug from 3.1.0 with sitemap, crawl-delay, host and unknown directives not terminating groups.
118
+ – Thanks to @bardrop for reporting and fixing.
119
+
115
120
  ## Version 3.1.0
116
121
 
117
122
  - Updated README to point to RFC 9309 instead of the draft specification.
118
123
  – Thanks to @joepie91 for reporting.
124
+ - Fixed CommonJS export type in typescript definitions.
125
+ – Thanks to @markedwards for fixing.
119
126
  - Added `isExplicitlyDisallowed()` method.
120
127
  – Thanks to @AuDigent for implementing.
121
128
  - Fixed grouping to match RFC 9309 by not treating non-standard directives like crawl-delay as terminating a group.
package/Robots.js CHANGED
@@ -402,7 +402,13 @@ function parseRobots(contents, robots) {
402
402
  break;
403
403
  }
404
404
 
405
- isGroupTermination = rule === 'allow' || rule === 'disallow';
405
+ // Other records (sitemap, crawl-delay, host, unknown) must not change
406
+ // the grouping: only a rule ends the user-agent lines of a group
407
+ if (rule === 'user-agent') {
408
+ isGroupTermination = false;
409
+ } else if (rule === 'allow' || rule === 'disallow') {
410
+ isGroupTermination = true;
411
+ }
406
412
  isNoneStandardGroupTermination = rule !== 'user-agent';
407
413
  }
408
414
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robots-parser",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "A specification compliant robots.txt parser with wildcard (*) matching support.",
5
5
  "keywords": [
6
6
  "robots.txt",
package/test/Robots.js CHANGED
@@ -1257,6 +1257,37 @@ describe('Robots', function () {
1257
1257
  testRobots('https://www.example.com/robots.txt', contents, allowed, disallowed);
1258
1258
  });
1259
1259
 
1260
+ it('should start a new group after rules even if other records follow them', function () {
1261
+ ['Sitemap: http://www.example.com/sitemap.xml', 'Crawl-delay: 1', 'Host: www.example.com', 'Foo: bar'].forEach(function (record) {
1262
+ var contents = [
1263
+ 'User-agent: a',
1264
+ 'Allow: /fish',
1265
+ record,
1266
+ 'User-agent: b',
1267
+ 'Disallow: /'
1268
+ ].join('\n');
1269
+
1270
+ var robots = robotsParser('http://www.example.com/robots.txt', contents);
1271
+
1272
+ expect(robots.isAllowed('http://www.example.com/test.html', 'a'), record).to.equal(true);
1273
+ expect(robots.isAllowed('http://www.example.com/test.html', 'b'), record).to.equal(false);
1274
+ });
1275
+ });
1276
+
1277
+ it('should not end a group of user-agent lines on other records', function () {
1278
+ var contents = [
1279
+ 'User-agent: a',
1280
+ 'Sitemap: http://www.example.com/sitemap.xml',
1281
+ 'User-agent: b',
1282
+ 'Disallow: /'
1283
+ ].join('\n');
1284
+
1285
+ var robots = robotsParser('http://www.example.com/robots.txt', contents);
1286
+
1287
+ expect(robots.isAllowed('http://www.example.com/test.html', 'a')).to.equal(false);
1288
+ expect(robots.isAllowed('http://www.example.com/test.html', 'b')).to.equal(false);
1289
+ });
1290
+
1260
1291
  it('should pass rfc9309-test-vectors.json tests', function () {
1261
1292
  const file = path.resolve(__dirname,'./rfc9309-test-vectors.json')
1262
1293
  const testVectors = JSON.parse(fs.readFileSync(file, 'utf8'));