Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps(robots-parser): patch robots-parser to work in both node and browser env #4819

Merged
merged 2 commits into from Mar 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions patches/robots-parser+1.0.2.patch
@@ -0,0 +1,36 @@
patch-package
--- a/node_modules/robots-parser/Robots.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a diff of a diff 😵

+++ b/node_modules/robots-parser/Robots.js
@@ -1,4 +1,4 @@
-var libUrl = require('url');
+var URL = (typeof self !== 'undefined' && self.URL) || require('url').URL;
var punycode = require('punycode');

/**
@@ -176,7 +176,7 @@ function isPathAllowed(path, rules) {


function Robots(url, contents) {
- this._url = libUrl.parse(url);
+ this._url = new URL(url);
this._url.port = this._url.port || 80;
this._url.hostname = punycode.toUnicode(this._url.hostname);

@@ -262,7 +262,7 @@ Robots.prototype.setPreferredHost = function (url) {
* @return {boolean?}
*/
Robots.prototype.isAllowed = function (url, ua) {
- var parsedUrl = libUrl.parse(url);
+ var parsedUrl = new URL(url);
var userAgent = formatUserAgent(ua || '*');

parsedUrl.port = parsedUrl.port || 80;
@@ -277,7 +277,7 @@ Robots.prototype.isAllowed = function (url, ua) {

var rules = this._rules[userAgent] || this._rules['*'] || [];

- return isPathAllowed(parsedUrl.path, rules);
+ return isPathAllowed(parsedUrl.pathname + parsedUrl.search, rules);
};

/**