robots-parser 3.0.0 → 3.0.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,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 3.0.1
4
+
5
+ - Fixed bug with `https:` URLs defaulting to port `80` instead of `443` if no port is specified.
6
+ Thanks to @dskvr for reporting
7
+
8
+ This affects comparing URLs with the default HTTPs port to URLs without it.
9
+ For example, comparing `https://example.com/` to `https://example.com:443/` or vice versa.
10
+
11
+ They should be treated as equivalent but weren't due to the incorrect port
12
+ being used for `https:`.
13
+
3
14
  ## Version 3.0.0
4
15
 
5
16
  - Changed to using global URL object instead of importing. – Thanks to @brendankenny
package/README.md CHANGED
@@ -94,6 +94,17 @@ Returns the preferred host name specified by the `host:` directive or null if th
94
94
 
95
95
  # Changes
96
96
 
97
+ ### Version 3.0.1
98
+
99
+ - Fixed bug with `https:` URLs defaulting to port `80` instead of `443` if no port is specified.
100
+ Thanks to @dskvr for reporting
101
+
102
+ This affects comparing URLs with the default HTTPs port to URLs without it.
103
+ For example, comparing `https://example.com/` to `https://example.com:443/` or vice versa.
104
+
105
+ They should be treated as equivalent but weren't due to the incorrect port
106
+ being used for `https:`.
107
+
97
108
  ### Version 3.0.0
98
109
 
99
110
  - Changed to using global URL object instead of importing. – Thanks to @brendankenny
package/Robots.js CHANGED
@@ -274,7 +274,13 @@ function parseUrl(url) {
274
274
  // Using non-existent subdomain so can never cause conflict unless
275
275
  // trying to crawl it but doesn't exist and even if tried worst that can
276
276
  // happen is it allows relative URLs on it.
277
- return new URL(url, 'http://robots-relative.samclarke.com/');
277
+ var url = new URL(url, 'http://robots-relative.samclarke.com/');
278
+
279
+ if (!url.port) {
280
+ url.port = url.protocol === 'https:' ? 443 : 80;
281
+ }
282
+
283
+ return url;
278
284
  } catch (e) {
279
285
  return null;
280
286
  }
@@ -282,8 +288,6 @@ function parseUrl(url) {
282
288
 
283
289
  function Robots(url, contents) {
284
290
  this._url = parseUrl(url) || {};
285
- this._url.port = this._url.port || 80;
286
-
287
291
  this._rules = Object.create(null);
288
292
  this._sitemaps = [];
289
293
  this._preferredHost = null;
@@ -361,8 +365,6 @@ Robots.prototype._getRule = function (url, ua) {
361
365
  var parsedUrl = parseUrl(url) || {};
362
366
  var userAgent = formatUserAgent(ua || '*');
363
367
 
364
- parsedUrl.port = parsedUrl.port || 80;
365
-
366
368
  // The base URL must match otherwise this robots.txt is not valid for it.
367
369
  if (
368
370
  parsedUrl.protocol !== this._url.protocol ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robots-parser",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A specification compliant robots.txt parser with wildcard (*) matching support.",
5
5
  "keywords": [
6
6
  "robots.txt",
@@ -40,7 +40,7 @@
40
40
  ".gitignore"
41
41
  ],
42
42
  "engines": {
43
- "node": ">=0.10"
43
+ "node": ">=10.0.0"
44
44
  },
45
45
  "prettier": {
46
46
  "tabWidth": 4,
@@ -49,8 +49,8 @@
49
49
  "trailingComma": "none"
50
50
  },
51
51
  "devDependencies": {
52
- "chai": "^4.3.4",
53
- "mocha": "^9.1.3",
52
+ "chai": "^4.3.6",
53
+ "mocha": "^10.0.0",
54
54
  "nyc": "^15.1.0"
55
55
  },
56
56
  "types": "./index.d.ts"
package/test/Robots.js CHANGED
@@ -791,4 +791,74 @@ describe('Robots', function () {
791
791
  // machines running the test, should normally be much less)
792
792
  expect(end - start).to.be.lessThan(500);
793
793
  });
794
+
795
+ it('should honor given port number', function () {
796
+ var contents = [
797
+ 'User-agent: *',
798
+ 'Disallow: /fish/',
799
+ 'Disallow: /test.html'
800
+ ].join('\n');
801
+
802
+ var allowed = [
803
+ 'http://www.example.com:8080/fish',
804
+ 'http://www.example.com:8080/Test.html'
805
+ ];
806
+
807
+ var disallowed = [
808
+ 'http://www.example.com/fish',
809
+ 'http://www.example.com/Test.html',
810
+ 'http://www.example.com:80/fish',
811
+ 'http://www.example.com:80/Test.html'
812
+ ];
813
+
814
+ testRobots('http://www.example.com:8080/robots.txt', contents, allowed, disallowed);
815
+ });
816
+
817
+ it('should default to port 80 for http: if no port given', function () {
818
+ var contents = [
819
+ 'User-agent: *',
820
+ 'Disallow: /fish/',
821
+ 'Disallow: /test.html'
822
+ ].join('\n');
823
+
824
+ var allowed = [
825
+ 'http://www.example.com:80/fish',
826
+ 'http://www.example.com:80/Test.html'
827
+ ];
828
+
829
+ var disallowed = [
830
+ 'http://www.example.com:443/fish',
831
+ 'http://www.example.com:443/Test.html',
832
+ 'http://www.example.com:80/fish/index.php',
833
+ 'http://www.example.com:80/fish/',
834
+ 'http://www.example.com:80/test.html'
835
+ ];
836
+
837
+ testRobots('http://www.example.com/robots.txt', contents, allowed, disallowed);
838
+ });
839
+
840
+ it('should default to port 443 for https: if no port given', function () {
841
+ var contents = [
842
+ 'User-agent: *',
843
+ 'Disallow: /fish/',
844
+ 'Disallow: /test.html'
845
+ ].join('\n');
846
+
847
+ var allowed = [
848
+ 'https://www.example.com:443/fish',
849
+ 'https://www.example.com:443/Test.html',
850
+ 'https://www.example.com/fish',
851
+ 'https://www.example.com/Test.html'
852
+ ];
853
+
854
+ var disallowed = [
855
+ 'http://www.example.com:80/fish',
856
+ 'http://www.example.com:80/Test.html',
857
+ 'http://www.example.com:443/fish/index.php',
858
+ 'http://www.example.com:443/fish/',
859
+ 'http://www.example.com:443/test.html'
860
+ ];
861
+
862
+ testRobots('https://www.example.com/robots.txt', contents, allowed, disallowed);
863
+ });
794
864
  });