@@ -397,7 +397,7 @@ Robots.prototype._getRule = function (url, ua, explicit) {
397397 * @return {boolean? }
398398 */
399399Robots . prototype . isAllowed = function ( url , ua ) {
400- var rule = this . _getRule ( url , ua ) ;
400+ var rule = this . _getRule ( url , ua , false ) ;
401401
402402 if ( typeof rule === 'undefined' ) {
403403 return ;
@@ -421,54 +421,37 @@ Robots.prototype.isAllowed = function (url, ua) {
421421 * @return {number? }
422422 */
423423Robots . prototype . getMatchingLineNumber = function ( url , ua ) {
424- var rule = this . _getRule ( url , ua ) ;
424+ var rule = this . _getRule ( url , ua , false ) ;
425425
426426 return rule ? rule . lineNumber : - 1 ;
427427} ;
428428
429429/**
430- * In standard mode, it returns the opposite of is allowed().
431- * In explicit mode, it will return:
432- * - true if the the agent is explicitly disallowed (wildcard non included),
433- * - throws an error if the user agent is not specified,
434- * - and false otherwise.
430+ * Returns the opposite of isAllowed()
431+ *
435432 * @param {string } url
436- * @param {string } ua
433+ * @param {string? } ua
437434 * @return {boolean }
438435 */
439- Robots . prototype . isDisallowed = function ( url , ua , explicit ) {
440- if ( ( explicit === true ) && ( ua === undefined ) ) {
441- throw new Error ( "User Agent must be specified in explicit mode" )
442- }
443-
444- var rule = this . _getRule ( url , ua , explicit ) ;
445- if ( typeof rule === 'undefined' ) {
446- return true ;
447- }
448- return ! ( ! rule || rule . allow ) ;
436+ Robots . prototype . isDisallowed = function ( url , ua ) {
437+ return ! this . isAllowed ( url , ua ) ;
449438} ;
450439
451- Robots . prototype . isExplicitlyDisallowed = function ( url , ua ) {
452- var parsedUrl = parseUrl ( url ) || { } ;
453- var userAgent = formatUserAgent ( ua ) ;
454-
455- // The base URL must match otherwise this robots.txt is not valid for it.
456- if (
457- parsedUrl . protocol !== this . _url . protocol ||
458- parsedUrl . hostname !== this . _url . hostname ||
459- parsedUrl . port !== this . _url . port
460- ) {
461- return ;
462- }
463-
464- var rules = this . _rules [ userAgent ] || [ ] ;
465- var path = urlEncodeToUpper ( parsedUrl . pathname + parsedUrl . search ) ;
466- var rule = findRule ( path , rules ) ;
440+ /**
441+ * Returns trues if explicitly disallowed
442+ * for the specified user agent (User Agent wildcards are discarded),
443+ * false if not allowed.
467444
445+ * This will return undefined if the URL is not valid for this robots.txt file.
446+ * @param {string } url
447+ * @param {string } ua
448+ * @return {boolean? }
449+ */
450+ Robots . prototype . isExplicitlyDisallowed = function ( url , ua ) {
451+ var rule = this . _getRule ( url , ua , true ) ;
468452 if ( typeof rule === 'undefined' ) {
469- return ;
453+ return undefined ;
470454 }
471-
472455 return ! ( ! rule || rule . allow ) ;
473456}
474457
0 commit comments