pac_utils.js: remove excessive escaping

Looks like the implementation was derived from Mozilla's
nsProxyAutoConfig.js, which is evaluated twice. It requires double
escaping.

In our case excessive escaping is harmful.

In particular it makes ip-matching regexp in isInNet() invalid and makes
it really slow as we go to dnsResolve() all the time, even when it's not
needed.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
This commit is contained in:
Kirill A. Shutemov 2017-02-21 15:23:27 +03:00
parent 13213724b0
commit ac3c8bb319

View File

@ -61,7 +61,7 @@ function convert_addr(ipchars) {
}
function isInNet(ipaddr, pattern, maskstr) {
var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/
var test = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
.exec(ipaddr);
if (test == null) {
ipaddr = dnsResolve(ipaddr);
@ -92,9 +92,9 @@ function localHostOrDomainIs(host, hostdom) {
}
function shExpMatch(url, pattern) {
pattern = pattern.replace(/\\./g, '\\\\.');
pattern = pattern.replace(/\\*/g, '.*');
pattern = pattern.replace(/\\?/g, '.');
pattern = pattern.replace(/\./g, '\\.');
pattern = pattern.replace(/\*/g, '.*');
pattern = pattern.replace(/\?/g, '.');
var newRe = new RegExp('^'+pattern+'$');
return newRe.test(url);
}