PAC - JavaScript - shExpMatch() 与 dnsDomainIs()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28533091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PAC - JavaScript - shExpMatch() vs dnsDomainIs()
提问by Wakan Tanka
What is the difference between shExpMatch()
and dnsDomainIs()
是有什么区别shExpMatch()
和dnsDomainIs()
The definition says:
定义说:
// 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";
If I understand it correct then
如果我理解正确的话
shExpMatch()
- can use some wildcards
shExpMatch()
- 可以使用一些通配符
dnsDomainIs()
- can use exact names
dnsDomainIs()
- 可以使用确切的名称
Is shExpMatch()
just superior to dnsDomainIs()
是shExpMatch()
仅仅优于dnsDomainIs()
回答by ingofreyer
Looking at the definitions from http://findproxyforurl.com/pac-functions/, they have very different functionality. dnsDomainIs() uses exact domain names - such as .google.com
, while shExpMatch() uses shell-like strings with wildcards such as *.google.com
.
查看来自http://findproxyforurl.com/pac-functions/的定义,它们具有非常不同的功能。dnsDomainIs() 使用精确的域名 - 例如.google.com
,而 shExpMatch() 使用类似 shell 的字符串和通配符,例如*.google.com
.
They look very different now, but with shExpMatch, you can also match items in a folder structure like example.com/sub/folder/*
or http://example.com/img/*.png
.
它们现在看起来非常不同,但是使用 shExpMatch,您还可以匹配文件夹结构中的项目,例如example.com/sub/folder/*
或http://example.com/img/*.png
。
The first one only matches the hostname without protocol, port or subfolders, while the second one matches the whole URL. However, you may be able to use shExpMatch() like dnsDomainIs(), but I am not sure, if you may be vulnerable then by inadvertedly allowing a URL like google.com.example.com
for google.com
- dnsDomainIs() would return false here, shExpMatch() may return true (not tested, just a hunch)
第一个只匹配主机名,没有协议、端口或子文件夹,而第二个匹配整个 URL。但是,您可能可以像 dnsDomainIs() 一样使用 shExpMatch(),但我不确定,如果您可能容易受到攻击,那么通过无意中允许像google.com.example.com
for google.com
- dnsDomainIs()这样的 URL会在此处返回 false,shExpMatch() 可能会返回 true (未测试,只是预感)
回答by James Fricker
beware the following in firefox 52.0...
请注意 Firefox 52.0 中的以下内容...
dnsDomainIs("www.notmycompany.com", "mycompany.com") returns true dnsDomainIs("www.myCompany.com", "mycompany.com") returns false
dnsDomainIs("www.notmycompany.com", "mycompany.com") 返回真 dnsDomainIs("www.myCompany.com", "mycompany.com") 返回假