@@ -361,7 +361,7 @@ Robots.prototype.setPreferredHost = function (url) {
361361 this . _preferredHost = url ;
362362} ;
363363
364- Robots . prototype . _getRule = function ( url , ua ) {
364+ Robots . prototype . _getRule = function ( url , ua , explicit ) {
365365 var parsedUrl = parseUrl ( url ) || { } ;
366366 var userAgent = formatUserAgent ( ua || '*' ) ;
367367
@@ -374,7 +374,12 @@ Robots.prototype._getRule = function (url, ua) {
374374 return ;
375375 }
376376
377- var rules = this . _rules [ userAgent ] || this . _rules [ '*' ] || [ ] ;
377+ var rules = this . _rules [ userAgent ] ;
378+ if ( ! explicit ) {
379+ rules = rules || this . _rules [ '*' ]
380+ }
381+ rules = rules || [ ]
382+
378383 var path = urlEncodeToUpper ( parsedUrl . pathname + parsedUrl . search ) ;
379384 var rule = findRule ( path , rules ) ;
380385
@@ -392,7 +397,7 @@ Robots.prototype._getRule = function (url, ua) {
392397 * @return {boolean? }
393398 */
394399Robots . prototype . isAllowed = function ( url , ua ) {
395- var rule = this . _getRule ( url , ua ) ;
400+ var rule = this . _getRule ( url , ua , false ) ;
396401
397402 if ( typeof rule === 'undefined' ) {
398403 return ;
@@ -416,7 +421,7 @@ Robots.prototype.isAllowed = function (url, ua) {
416421 * @return {number? }
417422 */
418423Robots . prototype . getMatchingLineNumber = function ( url , ua ) {
419- var rule = this . _getRule ( url , ua ) ;
424+ var rule = this . _getRule ( url , ua , false ) ;
420425
421426 return rule ? rule . lineNumber : - 1 ;
422427} ;
@@ -425,13 +430,30 @@ Robots.prototype.getMatchingLineNumber = function (url, ua) {
425430 * Returns the opposite of isAllowed()
426431 *
427432 * @param {string } url
428- * @param {string } ua
433+ * @param {string? } ua
429434 * @return {boolean }
430435 */
431436Robots . prototype . isDisallowed = function ( url , ua ) {
432437 return ! this . isAllowed ( url , ua ) ;
433438} ;
434439
440+ /**
441+ * Returns trues if explicitly disallowed
442+ * for the specified user agent (User Agent wildcards are discarded).
443+ *
444+ * This will return undefined if the URL is not valid for this robots.txt file.
445+ * @param {string } url
446+ * @param {string } ua
447+ * @return {boolean? }
448+ */
449+ Robots . prototype . isExplicitlyDisallowed = function ( url , ua ) {
450+ var rule = this . _getRule ( url , ua , true ) ;
451+ if ( typeof rule === 'undefined' ) {
452+ return true ;
453+ }
454+ return ! ( ! rule || rule . allow ) ;
455+ }
456+
435457/**
436458 * Gets the crawl delay if there is one.
437459 *
0 commit comments