How to use matcher - 10 common examples

To help you get started, we’ve selected a few matcher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eggjs / egg-security / lib / utils.js View on Github external
return domain_white_list.some(rule => {

    // Check whether we've got '*' as a wild character symbol
    if (rule.includes('*')) {
      return matcher.isMatch(domain, rule);
    }
    // If domain is an absolute path such as `http://...`
    // We can directly check whether it directly equals to `domain`
    // And we don't need to cope with `endWith`.
    return domain === rule || hostname.endsWith(rule);
  });
};
github liamray / nexl-js / backend / api / webhooks.js View on Github external
webhooks.forEach(webhook => {
		if (webhook.isDisabled === true) {
			logger.log.debug(`Skipping a [${webhook.relativePath}] webhook because it's disabled`);
			return;
		}

		// checking is webhook matches a target resource
		const opts = {
			caseSensitive: os.platform() !== 'win32'
		};
		if (matcher.isMatch(target.relativePath, webhook.relativePath, opts)) {
			postWebhook(webhook, target);
		} else {
			logger.log.debug(`The [${webhook.relativePath}] webhook doesn't match to [${target.relativePath}] resource`);
		}
	});
	return Promise.resolve();
github turnkeylinux / common / overlays / ninjux / home / user / .config / chromium / Default / Extensions / cfhdojbkjhnklbpkdaibdccddilifddb / 1.6.1_0 / background.js View on Github external
function isWhitelisted(url, parentUrl, type)
{
  // Ignore fragment identifier
  var index = url.indexOf("#");
  if (index >= 0)
    url = url.substring(0, index);

  var result = defaultMatcher.matchesAny(url, type || "DOCUMENT", extractHostFromURL(parentUrl || url), false);
  return (result instanceof WhitelistFilter ? result : null);
}
github turnkeylinux / common / overlays / ninjux / home / user / .config / chromium / Default / Extensions / cfhdojbkjhnklbpkdaibdccddilifddb / 1.6.1_0 / background.js View on Github external
if (sender.tab)
      {
        tabId = sender.tab.id;
        frameId = getFrameId(tabId, request.documentUrl);
      }

      if (isFrameWhitelisted(tabId, frameId, "DOCUMENT"))
      {
        sendResponse(false);
        break;
      }

      var requestHost = extractHostFromURL(request.url);
      var documentHost = extractHostFromURL(request.documentUrl);
      var thirdParty = isThirdParty(requestHost, documentHost);
      var filter = defaultMatcher.matchesAny(request.url, request.type, documentHost, thirdParty);
      if (filter instanceof BlockingFilter)
      {
        var collapse = filter.collapse;
        if (collapse == null)
          collapse = (localStorage.hidePlaceholders != "false");
        sendResponse(collapse);
      }
      else
        sendResponse(false);
      break;
    case "get-domain-enabled-state":
      // Returns whether this domain is in the exclusion list.
      // The page action popup asks us this.
      if(sender.tab)
      {
        sendResponse({enabled: !isWhitelisted(sender.tab.url)});
github adblockplus / adblockpluschrome / background.js View on Github external
}
      }

      sendResponse(selectors);
      break;
    case "should-collapse":
      if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT"))
      {
        sendResponse(false);
        break;
      }

      var requestHost = extractHostFromURL(msg.url);
      var documentHost = extractHostFromFrame(sender.frame);
      var thirdParty = isThirdParty(requestHost, documentHost);
      var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHost, thirdParty);
      if (filter instanceof BlockingFilter)
      {
        var collapse = filter.collapse;
        if (collapse == null)
          collapse = Prefs.hidePlaceholders;
        sendResponse(collapse);
      }
      else
        sendResponse(false);
      break;
    case "get-domain-enabled-state":
      // Returns whether this domain is in the exclusion list.
      // The browser action popup asks us this.
      if(sender.page)
      {
        sendResponse({enabled: !isWhitelisted(sender.page.url)});
github turnkeylinux / common / overlays / ninjux / home / user / .config / chromium / Default / Extensions / cfhdojbkjhnklbpkdaibdccddilifddb / 1.6.1_0 / background.js View on Github external
with(require("filterClasses"))
{
  this.Filter = Filter;
  this.RegExpFilter = RegExpFilter;
  this.BlockingFilter = BlockingFilter;
  this.WhitelistFilter = WhitelistFilter;
}
with(require("subscriptionClasses"))
{
  this.Subscription = Subscription;
  this.DownloadableSubscription = DownloadableSubscription;
}
var FilterStorage = require("filterStorage").FilterStorage;
var ElemHide = require("elemHide").ElemHide;
var defaultMatcher = require("matcher").defaultMatcher;
var Prefs = require("prefs").Prefs;
var Synchronizer = require("synchronizer").Synchronizer;
var Utils = require("utils").Utils;
var Notification = require("notification").Notification;

// Some types cannot be distinguished
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OTHER;

var isFirstRun = false;
var seenDataCorruption = false;
require("filterNotifier").FilterNotifier.addListener(function(action)
{
  if (action == "load")
  {
    importOldData();
github operasoftware / operaextensions.js / src / background / urlfilter / UrlFilterManager.js View on Github external
with(require("filterClasses")) {
    this.Filter = Filter;
    this.RegExpFilter = RegExpFilter;
    this.BlockingFilter = BlockingFilter;
    this.WhitelistFilter = WhitelistFilter;
  }

  with(require("subscriptionClasses")) {
    this.Subscription = Subscription;
    //this.DownloadableSubscription = DownloadableSubscription;
  }

  this.FilterStorage = require("filterStorage").FilterStorage;

  this.defaultMatcher = require("matcher").defaultMatcher;

  // https://github.com/adblockplus/adblockpluschrome/blob/master/webrequest.js

  var self = this;

  var frames = {};

  function recordFrame(tabId, frameId, parentFrameId, frameUrl) {
    if (!(tabId in frames))
      frames[tabId] = {};
    frames[tabId][frameId] = {url: frameUrl, parent: parentFrameId};
  }

  function getFrameData(tabId, frameId) {
    if (tabId in frames && frameId in frames[tabId])
      return frames[tabId][frameId];
github adblockplus / adblockpluschrome / background.js View on Github external
}
with(require("subscriptionClasses"))
{
  this.Subscription = Subscription;
  this.DownloadableSubscription = DownloadableSubscription;
  this.SpecialSubscription = SpecialSubscription;
}
with(require("whitelisting"))
{
  this.isWhitelisted = isWhitelisted;
  this.isFrameWhitelisted = isFrameWhitelisted;
  this.processKeyException = processKeyException;
}
var FilterStorage = require("filterStorage").FilterStorage;
var ElemHide = require("elemHide").ElemHide;
var defaultMatcher = require("matcher").defaultMatcher;
var Prefs = require("prefs").Prefs;
var Synchronizer = require("synchronizer").Synchronizer;
var Utils = require("utils").Utils;
var Notification = require("notification").Notification;
var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNotification;

// Some types cannot be distinguished
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OTHER;

// Chrome on Linux does not fully support chrome.notifications until version 35
// https://code.google.com/p/chromium/issues/detail?id=291485
var canUseChromeNotifications = require("info").platform == "chromium"
  && "notifications" in chrome
  && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").applicationVersion) > 34);
github swagger-api / swagger-editor / src / plugins / validate-json-schema / semantic-validators / validators / walker.js View on Github external
function walk(value, path) {
    let curr = path[path.length - 1]

    if(value === null) {
      return null
    }

    ///// Restricted $refs

    if(curr === "$ref") {
      let refBlacklist = getRefPatternBlacklist(path) || []
      let matches = match([value], refBlacklist)

      let humanFriendlyRefBlacklist = refBlacklist
        .map(val => `"${val}"`)
        .join(", ")

      if(refBlacklist && refBlacklist.length && matches.length) {
        // Assertation 1
        errors.push({
          path,
          message: `${path[path.length - 2]} $refs cannot match any of the following: ${humanFriendlyRefBlacklist}`
        })
      }
    }

    if(typeof value !== "object") {
      return null
github adblockplus / adblockplus / lib / notification.js View on Github external
{
            try
            {
              host = Services.io.newURI(url, null, null).host;
            }
            catch (e)
            {
              // Ignore, an exception is expected for about: and similar schemes
              host = "";
            }
          }
          let exception = defaultMatcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, host, false, null);
          if (exception instanceof WhitelistFilter)
            continue;

          let matcher = new Matcher();
          for (let urlFilter of notification.urlFilters)
            matcher.add(Filter.fromText(urlFilter));
          if (!matcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, host, false, null))
            continue;
        }
        else
          continue;
      }

      if (notification.targets instanceof Array)
      {
        let match = false;
        for (let target of notification.targets)
        {
          if (checkTarget(target, "extension", addonName, addonVersion) &&
              checkTarget(target, "application", application, applicationVersion) &&