gpt4 book ai didi

javascript - PAC - JavaScript - shExpMatch() 与 dnsDomainIs()

转载 作者:数据小太阳 更新时间:2023-10-29 05:29:42 24 4
gpt4 key购买 nike

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()

最佳答案

查看 http://findproxyforurl.com/pac-functions/ 中的定义,它们具有非常不同的功能。 dnsDomainIs() 使用准确的域名 - 例如 .google.com,而 shExpMatch() 使用带有通配符的 shell-like 字符串,例如 *.google.com

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

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

关于javascript - PAC - JavaScript - shExpMatch() 与 dnsDomainIs(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28533091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com