Leask/Flora_Pac — pull request #17 by usufu (2014-07-10 14:57:19+00:00)
Title: Fix a bug for Binary search algorithm.

### Description:
For some kind of ip address of china, which should connect directly, but failed on **match** function in PAC file. it is a minor bug in that function.

### Example:
Name:	**yinxiang.com**
Address: **119.254.30.39 [2013142567]**
apnet cn list: **119.254.0.0/255.254.0.0 [2013134848, 4294836224]**
The address already **IN** the list.

I added some output messages for debugging such as below:
* Before fix
```javascript
function match(ip, list) {
var left = 0, right = list.length;
do {
var mid = Math.floor((left + right) / 2),
ip = (ip & list[mid][1]) >>> 0,
m = (list[mid][0]) >>> 0;
console.log('mid list ' +list[mid], "ip " +ip,"expect " +m);
if (ip == m) {
return true;
} else if (ip > m) {
left = mid + 1;
} else {
right = mid;
}
} while (left + 1 <= right);

return false;
};
```
*output*
```
2013142567
"mid list 2054619136,4294901760"
"ip 2013134848"
"expect 2054619136"
"mid list 1793064960,4293918720"
"ip 2012217344"
"expect 1793064960"
"mid list 1962606592,4294901760"
"ip 2012217344"
"expect 1962606592"
"mid list 2001731584,4294901760"
"ip 2012217344"
"expect 2001731584"
"mid list 2031091712,4294443008"
"ip 2012217344"
"expect 2031091712"
"mid list 2015887360,4294705152"
"ip 2012217344"
"expect 2015887360"
"mid list 2007105536,4294836224"
"ip 2012217344"
"expect 2007105536"
"mid list 2013069312,4294901760"
"ip 2012217344"
"expect 2013069312"
"mid list 2011889664,4294901760"
"ip 2012217344"
"expect 2011889664"
"mid list 2013003776,4294901760"
"ip 2012217344"
"expect 2013003776"
"mid list 2012741632,4294705152"
"ip 2012217344"
"expect 2012741632"
"PROXY 127.0.0.1:8103; SOCKS5 127.0.0.1:8104; SOCKS 127.0.0.1:8104; DIRECT"
```
The proxy returned, not DIRECT as we want.
* After fix
```javascript
function match(ip, list) {
var left = 0, right = list.length;
do {
var mid = Math.floor((left + right) / 2),
ip_f = (ip & list[mid][1]) >>> 0,
m = (list[mid][0]) >>> 0;
console.log('mid list ' +list[mid], "ip " +ip_f,"expect " +m);
if (ip_f == m) {
return true;
} else if (ip_f > m) {
left = mid + 1;
} else {
right = mid;
}
} while (left + 1 <= right);

return false;
};
```
*output*
```

Console Run Clear
2013142567
"mid list 2054619136,4294901760"
"ip 2013134848"
"expect 2054619136"
"mid list 1793064960,4293918720"
"ip 2012217344"
"expect 1793064960"
"mid list 1962606592,4294901760"
"ip 2013134848"
"expect 1962606592"
"mid list 2001731584,4294901760"
"ip 2013134848"
"expect 2001731584"
"mid list 2031091712,4294443008"
"ip 2012741632"
"expect 2031091712"
"mid list 2015887360,4294705152"
"ip 2013003776"
"expect 2015887360"
"mid list 2007105536,4294836224"
"ip 2013134848"
"expect 2007105536"
"mid list 2013069312,4294901760"
"ip 2013134848"
"expect 2013069312"
"mid list 2015232000,4294901760"
"ip 2013134848"
"expect 2015232000"
"mid list 2013265920,4293918720"
"ip 2012217344"
"expect 2013265920"
"mid list 2013134848,4294836224"
"ip 2013134848"
"expect 2013134848"
"DIRECT"
```
Yep, We got it. :)