PAC-JavaScript-shExpMatch()与dnsDomainIs()的比较

PAC-JavaScript-shExpMatch()与dnsDomainIs()的比较,javascript,pac,Javascript,Pac,shExpMatch()和dnsDomainIs() 定义是: // dnsDomainIs() // Evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual host names. // Example: if (dnsDomainIs(host, ".google.com")) return "DIRECT"; // shExpMatc

shExpMatch()
dnsDomainIs()

定义是:

// dnsDomainIs()
// Evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual host names.

// Example:
if (dnsDomainIs(host, ".google.com")) return "DIRECT";



// shExpMatch()
// Attempts to match hostname or URL to a specified shell expression and returns true if matched.

// Example:
if (shExpMatch(url, "*vpn.domain.com*") ||
      shExpMatch(url, "*abcdomain.com/folder/*"))
  return "DIRECT";
如果我理解正确的话

shExpMatch()
-可以使用一些通配符

dnsDomainIs()
-可以使用准确的名称


shExpMatch()
仅仅优于
dnsDomainIs()

从定义来看,它们的功能非常不同。dnsDomainIs()使用精确的域名,如
.google.com
,而shExpMatch()则使用带通配符的类似shell的字符串,如
*.google.com

它们现在看起来非常不同,但是使用SHXPMATCH,您还可以匹配文件夹结构中的项目,如
example.com/sub/folder/*
http://example.com/img/*.png


第一个只匹配没有协议、端口或子文件夹的主机名,而第二个匹配整个URL。但是,您可能可以像dnsDomainIs()一样使用shExpMatch(),但我不确定,如果您可能容易受到攻击,那么如果不小心允许像
google.com.example.com
这样的URL,对于
google.com
,dnsDomainIs()将在此处返回false,shExpMatch()可能返回true(未经测试,只是预感)

在firefox 52.0中要注意以下几点

dnsDomainIs(“www.notmycompany.com”、“mycompany.com”)返回true
dnsDomainIs(“www.myCompany.com”、“myCompany.com”)返回false

可以将
放入,这样
dnsDomainIs(“www.notmycompany.com”、“myCompany.com”)
返回false。